Python 将 DLL 复制到 Windows 上的站点包 [英] Python copy a DLL to site-packages on Windows
问题描述
我正在编写一个需要与第三方 DLL 链接的 python 扩展模块.如何使用 distutils(即在我的 setup.py 文件中)将此 DLL 复制到 site-packages 目录?
I am writing a python extension module that needs to link with a third-party DLL. How can I copy this DLL to the site-packages directory using distutils (i.e. in my setup.py file)?
推荐答案
将您的 DLL 放入您的 setup()
的 package_data
参数中(请参阅 安装包数据 distutils 文档的部分以了解详细信息).
Put your DLL in the package_data
argument of your setup()
(see the Installing Package Data section of the distutils documentation for details).
如果您需要将 DLL 放在包目录之外,您可以使用 data_files
选项.比如把它放在site-packages
目录下:
If you need to put the DLL outside of the package directory , you can use the data_files
option. For example to put it in the site-packages
directory:
import distutils.sysconfig
setup(
# [...]
data_files = [(distutils.sysconfig.get_python_lib(), ["/path/to/the/DLL"])],
)
这篇关于Python 将 DLL 复制到 Windows 上的站点包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!