2011-09-24 58 views
3

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

我用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

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

data_files=["myhome", ["Win32/file1.pyd", "Win32/file2.dll"])] 

2.我试图在包中找到“myhomye”的位置init文件,所以我可以使用它们。这需要一些令人讨厌的代码,因为它们要么在当前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) 
相关问题