Jaf*_*ado 9 python pip pypi scikit-learn
如何在 PyPI 上发布包,以便自动安装所有依赖项,而不是由用户手动安装。
我在setup.pywith 中指定依赖项,install_requires如下所示:
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'
)
Run Code Online (Sandbox Code Playgroud)
我有一个requirements.txt包含在我的文件中的文件MANIFEST.in:
numpy==1.15.4
sklearn==0.20.1
pandas==0.23.4
Run Code Online (Sandbox Code Playgroud)
但是,在我尝试安装包时在 test.pypi 上发布后,出现以下错误:
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)
Run Code Online (Sandbox Code Playgroud)
这意味着 PyPI 不会安装 numpy 依赖项。如何启用我的依赖项的自动安装?在构建和发布包时我应该使用虚拟环境吗?我该怎么做呢?
PS 我对此完全陌生,因此我将欣赏显式代码或指向简单教程页面的链接。谢谢你。
您可以通过--extra-index-url. 将它指向 TestPyPI,以便从那里提取您的包,来自 PyPI 的 deps:
$ pip install myPackage --extra-index-url=https://test.pypi.org/simple/
Run Code Online (Sandbox Code Playgroud)
但是,问题的真正根源在于您为scikit-learn包包含了错误的 dist 名称。替换sklearn为scikit-learn:
setup(
...,
install_requires=['numpy', 'pandas', 'scikit-learn'],
)
Run Code Online (Sandbox Code Playgroud)
我意识到从 test.PyPI 安装软件包并不会安装所有软件包,因为其中一些软件包托管在 PyPI 而不是 test.PyPI 上。
当我在 PyPI 上发布包作为预发布版本 (1.0a1) 时,而不是在 test.PyPI 上,依赖项已正确安装。因此,问题纯粹在于 test.PyPI。