python - 安装工具/distutils : Installing files into the distribution's DLLs directory on Windows

标签 python setuptools distutils pip easy-install

我正在编写一个 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) 

关于python - 安装工具/distutils : Installing files into the distribution's DLLs directory on Windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7537799/

相关文章:

python - subprocess ls Examples/* 没有这样的文件或目录

python - 与 setup.py 和包共享包版本的正确方法是什么?

c++ - 如何在 OSX 上为 Python 编译 C++ 扩展(而不是 C)?

python - 如何在 python distutils 中包含隐藏文件?

python - 根据其他列值创建 Pandas Dataframe 行

python - 将数据从数据帧映射到另一个数据帧以提取信息用户

python - 加快 Pandas 数据框中的搜索速度

python - 强制 setuptools 需要来自存储库而不是 PyPI 的包

python - 如何使用 `dev_requirements.txt` 中的 `extras_require` 从 `setup.cfg` 文件的 `pip-compile` 部分创建 `pip-tools`?

python - distutils 对 "requires"元数据做了什么?