Setuptools / distutils: Installing files into the distribution's DLLs directory on Windows
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 f开发者_开发技巧ollowing 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?
I was able to solve this issue by doing the following changes:
1. All data_files path changed to be relative
data_files=["myhome", ["Win32/file1.pyd", "Win32/file2.dll"])]
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.
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. I then need to add this directory to the path, so my modules will be loaded from there.
sys.path.append(myhome)
精彩评论