如何让PyPI自动安装依赖项 [英] How to get PyPI to automatically install dependencies
问题描述
如何在PyPI上发布软件包,以便自动安装所有依赖项,而不是由用户手动安装.
How can I publish a package on PyPI such that all dependencies are automatically installed, rather than manually by the user.
我用install_requires
在setup.py
中指定依赖项,如下所示:
I specify the dependencies in setup.py
with install_requires
as follows:
setuptools.setup(name='myPackage',
version='1.0',
packages=setuptools.find_packages(),
include_package_data=True,
classifiers=[
'Programming Language :: Python :: 3',
'Operating System :: OS Independent',
'Topic :: Scientific/Engineering :: Bio-Informatics'
],
install_requires=['numpy', 'pandas', 'sklearn'],
python_requires='>=3'
)
我有一个requirements.txt
文件,该文件包含在我的MANIFEST.in
中:
And I have a requirements.txt
file which is included in my MANIFEST.in
:
numpy==1.15.4
sklearn==0.20.1
pandas==0.23.4
但是,当我尝试安装软件包时在test.pypi上发布后,出现以下错误:
However, after publishing on test.pypi when I try to install the package, I get the following error:
Could not find a version that satisfies the requirement numpy (from myPackage==1.0.0) (from versions: )
No matching distribution found for sklearn (from myPackage==1.0.0)
这意味着PyPI不会安装numpy依赖项. 如何启用自动安装依赖项? 在构建和发布程序包时,我应该使用虚拟环境吗?我该怎么做?
This means that PyPI does not install the numpy dependency. How do I enable automatic installation of my dependencies? Should I use a virtual environment when building and publishing the package? How do I do this?
P.S.我是新手,所以我将欣赏显式代码或指向简单教程页面的链接.谢谢.
P.S. I am entirely new to this so I will appreciate explicit code or links to simple tutorial pages. Thank you.
推荐答案
我意识到从test.PyPI安装软件包不会安装所有软件包,因为其中一些软件包托管在PyPI上,而不是test.PyPI.
I realized that installing packages from test.PyPI does not install all packages, since some of these packages are hosted on PyPI and not test.PyPI.
当我在PyPI上以预发行版(1.0a1)发行软件包时,而不是在test.PyPI上发行软件包,则正确安装了依赖项.因此,问题完全出在test.PyPI.
When I published the package on PyPI as a pre-release version (1.0a1), instead on test.PyPI, the dependencies were correctly installed. Hence, the problem was purely with test.PyPI.
这篇关于如何让PyPI自动安装依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!