如何在 Python 中的 setup.py 中包含和安装本地依赖项?

问题描述:

我正在创建一个 setup.py 来分发我的应用程序.此应用程序有许多依赖项可以通过 pip 安装,也有一些无法从 PyPI 安装的自定义依赖项.

I am creating a setup.py to distribute my application. This application has a number of dependencies which can be installed via pip, it also has some custom dependencies which can not be installed from PyPI.

因此,我创建了一个 custom_package_0.1.whl,它将包含在分发中,并且必须在 setup.py 安装 setup.py 中的所有内容后作为依赖项安装代码>install_requires.

So, I have created a custom_package_0.1.whl which will be included into the distribution and must be installed as a dependency after setup.py installs everything from install_requires.

想象以下应用结构:

my_app/
    win_deps/custom_package_0.1.whl
    my_app/
        __init__.py
        main.py
        setup.py
        setup.cfg

我该怎么做?

有可能但不确定您应该使用哪个 setuptools 版本.步骤:

it is possible but not sure what setuptools version you should use. steps:

在 setup.py

setup(
  ...,
  install_requires=['my-package'],
  dependency_links=[
    # location to your egg file
    os.path.join(os.getcwd(), 'deps', 'my_package-1.0.0-py3.5.egg')
  ]
)

重要的是,您的位置不应通过 URL 模式测试,且egg 文件名应具有结构 --.egg

important thing is that your location should not pass URL pattern test and egg file name should have structure <package_name_with_no_hyphens>-<version>-<py_version>.egg