Setuptools / distutils:在Windows上将文件安装到发行版的DLLs目录中

Uri*_*hen 5 python distutils pip setuptools easy-install

我正在写一个setup.py,它使用setuptools / distutils安装我编写的python包。它需要将两个DLL文件(实际上是DLL文件和PYD文件)安装到可供python加载的位置。以为这是DLLs我的python发行版(例如c:\Python27\DLLs)上安装目录下的目录。

我已经使用data_files选项安装这些文件,并且在使用pip时可以正常工作:

data_files=[(sys.prefix + "/DLLs", ["Win32/file1.pyd", "Win32/file2.dll"])]
Run Code Online (Sandbox Code Playgroud)

但是使用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.
Run Code Online (Sandbox Code Playgroud)

那么,安装这些文件的正确方法是什么?

Uri*_*hen 2

我能够通过执行以下更改来解决此问题:
1. 所有 data_files 路径更改为相对路径

data_files=["myhome", ["Win32/file1.pyd", "Win32/file2.dll"])]
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

3. 然后我需要将此目录添加到路径中,以便从那里加载我的模块。

sys.path.append(myhome) 
Run Code Online (Sandbox Code Playgroud)