我正在编写一个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.
那么,什么是安装这些文件的正确方法?
通过以下更改,我能够解决此问题:1.将所有data_files路径更改为相对路径
data_files=["myhome", ["Win32/file1.pyd", "Win32/file2.dll"])]
2。我尝试在程序包初始化文件中找到“ myhome”的位置,以便能够使用它们。这需要一些讨厌的代码,因为它们位于当前Python的根目录下或专用于该软件包的egg目录下。因此,我只是查看目录的退出位置。
POSSIBLE_HOME_PATH = [
os.path.join(os.path.dirname(__file__), '../myhome'),
os.path.join(sys.prefix, 'myhome'),
]
for p in POSSIBLE_HOME_PATH:
myhome = p
if os.path.isdir(myhome) == False:
print "Could not find home at", myhome
else:
break
3。然后,我需要将此目录添加到路径,以便从那里加载我的模块。
sys.path.append(myhome)