应该pip安装我的python应用程序自动安装依赖项?

时间:2018-03-21 09:38:45

标签: python pip

我是python包装和发行的新手。我有一个python应用程序,我想要pip安装,所以我为它创建了一个setup.py。

现在setup.py有install_requires警告是否缺少依赖项,但我想知道我是否能够/应该提供一种自动安装缺少的依赖项的方法。目前,该应用需要一个自行开发的共享包,而不需要外部包。

修改

我的setup.py:

from setuptools import setup

setup(
    name="TcpMonitor",
    version="1.0",
    packages=["tcpmonitor"],
    py_modules=["tcp_monitor"],
    install_requires=[
        "CommonPyLib",
    ],
    entry_points='''
        [console_scripts]
        tcp_monitor_gui=tcpmonitor:main
    '''
)

Pip安装输出:

Collecting CommonPyLib (from TcpMonitor==1.0)
  Could not find a version that satisfies the requirement CommonPyLib (from TcpMonitor==1.0) (from versions: )
No matching distribution found for CommonPyLib (from TcpMonitor==1.0)

1 个答案:

答案 0 :(得分:3)

只要依赖项列在install_requires列表中,它就会自动检查该模块,如果不存在,它将安装它,前提是该模块可以从PyPi安装。如果不是(在PyPi上找不到该包的地方),则会出现Could not find a version that satisfies the requirement错误。

我在PyPi上找不到任何具有此名称的软件包,因此您需要添加要安装在PyPi上的依赖项,以便通过pip安装,如果您将软件包托管在别处(例如GitHub),这可能会提供解决方案:How can I make setuptools install a package that's not on PyPI?

运行pip install commonpylib返回

  

找不到满足要求commonlib的版本(来自版本:)   找不到针对commonpylib的匹配分布

所以你没有设置脚本问题,但是在PyPi上找到包的问题(似乎不存在),或者至少Python不知道你在哪里托管它。

另一种选择是将该包与您正在分发的内容集成,而不将其作为依赖项(即将其添加到__init__.py文件中)。

相关问题