Pip无法安装setup.py中声明的依赖项(即install_requires)

4
在Python项目中,我正在使用以下方式在我的setup.py中使用install_requires
install_requires=['numpy', 'scipy', 'matplotlib']

我接下来按照以下步骤创建源代码、二进制文件和安装包。
python setup.py sdist bdist bdist_wheel

我发布时使用 twine

twine upload --repository dist/testpypi mypackage-0.1.1-py2-none-any.whl

在Python 2.7 conda环境中,我尝试测试安装。
pip install -i https://test.pypi.org/simple/ mypackage==0.1.1

然而,我收到以下错误消息:
ERROR: Could not find a version that satisfies the requirement matplotlib (from mypackage) (from versions: none)
ERROR: No matching distribution found for matplotlib (from mypackage)
当我运行pip listconda list时,确实没有列出matplotlib包。
我做错了什么? 我认为(这是我的理解断点),install_requires会列出先决条件,并且pip install会注意到并自动安装要求。然而,似乎install_requires是在充当防止安装未安装其声明的依赖项的包的门卫。
在一些互联网搜索中,他们似乎建议我通过MANIFEST.in包括一个requirements.txt(例如include requirements.txt),然后pip install将自动安装依赖关系。 但是,在尝试了该方法之后,我仍然收到相同的错误消息。 我使用以下requirements.txt进行了尝试。
matplotlib

以下是相关的内容:

同样也如下所示。

matplotlib>=2.2.3

我该如何配置/设置setup.py和我的分发,使得通过install_requires声明的依赖项可以被pip installconda install自动安装?


你介意让我们试试吗?可以告诉我们软件包的名称吗? - Sraw
1个回答

7

问题在于pip会在与所选包同一仓库中查找软件包。因此,如果您提供 https://test.pypi.org/simple/ ,它将在此处查找软件包,而不是在 https://pypi.org/simple/

您需要使用--extra-index-url参数。

--extra-index-url <url>     Extra URLs of package indexes to use in addition to --index-url. Should follow the same rules as --index-url.

那么尝试:

pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ mypackage==0.1.1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接