python - 在 Python 包中包含 *.pyd 文件

标签 python python-2.7 include pypi pyd

我有一个 python 模块 module.pyd,一旦将其手动放入 python 安装文件夹的站点包中,它就可以正常工作。

当我将我的解决方案上传到云环境时,问题就开始了,buildpack 请求我将每个模块作为一个包传递,以便使用 pip install module 安装。我创建了一个文件夹,其中包含一个简单的 __init__.py 文件,该文件仅导入 module.pyd 的所有内容,因此我的模块被视为一个文件夹。

然后我读到这里http://peterdowns.com/posts/first-time-with-pypi.html如何上传我自己的模块,我成功了,但是当我安装我的模块时,module.pyd 文件没有被复制。我也尝试通过存储库直接安装它 pip install git+repository 但同样的事情发生了。

我在这里读过https://docs.python.org/2/distutils/sourcedist.html#specifying-the-files-to-distribute我可能不得不明确地说我想在 MANIFEST.in 文件中复制 *.pyd 文件,我已经完成了,但它似乎还没有工作。

我目前使用的是 python 2.7.10

我是 python 的新手,所以非常感谢你们的帮助

最佳答案

只需使用MANIFEST.in:

recursive-include module *.pyd

这将包括 module 目录中的所有 pyd 文件。

您的包布局应如下所示:

module/
--- __init__.py
--- _module.pyd
--- module.py
MANIFEST.in
README.rst
setup.py

并且不要忘记在 setup.pysetup() 中添加 include_package_data=True 以强制使用 MANIFEST.in 在构建轮子和 win32 安装程序时(否则 MANIFEST.in 将仅用于源 tarball/zip)。

setup() 的最小示例:

README_rst = ''
with open('README.rst', mode='r', encoding='utf-8') as fd:
    README_rst = fd.read()

setup(
    name='module',
    version='0.0.1',
    description='Cool short description',
    author='Author',
    author_email='author@mail.com',
    url='repo.com',
    packages=['module'],
    long_description=README_rst,
    include_package_data=True,
    classifiers=[
        # Trove classifiers
        # The full list is here: https://pypi.python.org/pypi?%3Aaction=list_classifiers
        'Development Status :: 3 - Alpha',
    ]
)

关于python - 在 Python 包中包含 *.pyd 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37031456/

相关文章:

python - python dict 和 PyQt 小部件之间连接的最佳方式是什么?

python - Pandas:使用 [column name][row_number] 选择数组的值仅适用于 multiindex

python - Salesforce bulk api 使用 python simplesalesforce 包

regex - 仅否定正则表达式中的特定字符串

python - 在 Ipython 中设置新主题时遇到问题?

javascript - 在 Angular 6 上将 html 模板包含到另一个模板中

javascript - 我可以在Flask中创建指向页面上特定项目的自定义链接吗?

Python数据库连接和结果集转换为字符串

c++ - 在此范围内未声明“敌人”?

c++ - 交叉引用 C++ 程序中包含的 header