gpt4 book ai didi

python - Pip 不会安装 setup.py 中使用 install_requires 声明的依赖项

转载 作者:行者123 更新时间:2023-12-01 00:41:25 25 4
gpt4 key购买 nike

在Python项目中,我使用install_requires在我的setup.py如下。

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)

When I do a pip list and conda list, indeed, there is no matplotlib package listed.

What am I doing wrong? I thought (this point is where my understanding breaks down) that install_requires would list the prerequistes and pip install would pick up on that and automatically install the requirements? However, it seems that install_requires is acting as a guard against installing a package if its declared dependencies are not already installed.

In some internet searches, they seem to suggest that I include a requirements.txt via MANIFEST.in (e.g. include requirements.txt) and then pip install will auto-install the dependencies. However, after trying that approach, I still get the same error message. I tried with requirements.txt as follows.

matplotlib

也如下。

matplotlib>=2.2.3

如何配置/设置 setup.py我的分布是 pip installconda install将通过 install_requires 自动安装声明的依赖项?

最佳答案

问题是 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

关于python - Pip 不会安装 setup.py 中使用 install_requires 声明的依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57321119/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com