Setuptools / distutils:将文件安装到 Windows 上的发行版 DLL 目录中
我正在编写一个 setup.py ,它使用 setuptools/distutils 来安装我编写的 python 包。 它需要将两个DLL文件(实际上是一个DLL文件和一个PYD文件)安装到可供python加载的位置。认为这是我的Python发行版安装目录下的DLLs
目录(例如c:\Python27\DLLs
)。
我已经使用 data_files 选项来安装这些文件,并且在使用 pip 时一切正常:
data_files=[(sys.prefix + "/DLLs", ["Win32/file1.pyd", "Win32/file2.dll"])]
但是使用 easy_install 我收到以下错误:
error: Setup script exited with error: SandboxViolation: open('G:\\Python27\\DLLs\\file1.pyd', 'wb') {}
The package setup script has attempted to modify files on your system that are not within the EasyInstall build area, and has been aborted.
那么,安装这些文件的正确方法是什么?
I'm writing a setup.py which uses setuptools/distutils to install a python package I wrote.
It need to install two DLL files (actually a DLL file and a PYD file) into location which is available for python to load. Thought this is the DLLs
directory under the installation directory on my python distribution (e.g. c:\Python27\DLLs
).
I've used data_files option to install those files and all work when using pip:
data_files=[(sys.prefix + "/DLLs", ["Win32/file1.pyd", "Win32/file2.dll"])]
But using easy_install I get the following error:
error: Setup script exited with error: SandboxViolation: open('G:\\Python27\\DLLs\\file1.pyd', 'wb') {}
The package setup script has attempted to modify files on your system that are not within the EasyInstall build area, and has been aborted.
So, what's the right way to install those files?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够通过执行以下更改来解决此问题:
1. 所有 data_files 路径都更改为相对路径
2. 我尝试在包初始化文件中找到“myhome”的位置,以便我能够使用它们。这需要一些讨厌的代码,因为它们要么位于当前Python的根目录下,要么位于专用于该包的egg目录下。所以我只是查看目录存在的位置。
3. 然后我需要将此目录添加到路径中,以便从那里加载我的模块。
I was able to solve this issue by doing the following changes:
1. All data_files path changed to be relative
2. I try to find the location of "myhome" in the package init file so I'll be able to use them. This require some nasty code, because they are either under current Python's root directory or under an egg directory dedicated to the package. So I just look where a directory exits.
3. I then need to add this directory to the path, so my modules will be loaded from there.