当我将我的 python 包推送到 test.pypi.org 时,我无法在不同的机器和不同的虚拟环境上安装该包。我收到错误消息,说我的包的依赖项没有发行版,并且错误消息说找不到满足要求的版本。
我试图在我的 setup.py 文件中解析我的 requirements.txt,然后运行python setup.py sdist bdist_wheel并twine upload --repository-url https://test.pypi.org/legacy/ dist/*构建并将其上传到 test.pipy.org 但问题仍然存在。
我的 setup.py 看起来像这样
...
dependencies=''
with open("requirements.txt","r") as f:
dependencies = f.read().splitlines()
setup(
name="FlagWaver",
version="0.0.54",
description=DESCRIPTION,
long_description = LONG_DESCRIPTION,
long_description_content_type = "text/markdown",
url="https://github.com/ShahriyarShawon/flag-wave",
author="Shahriyar Shawon",
author_email="ShahriyarShawon321@gmail.com",
license="Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International",
packages = [
"FlagWaver"
],
classifiers = [
"Programming Language :: Python :: 3"
],
install_requires = dependencies
)
Run Code Online (Sandbox Code Playgroud)
我运行这个 bash 脚本来构建和上传
#!/bin/zsh
pipenv shell
python setup.py …Run Code Online (Sandbox Code Playgroud) 如何在 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 我对此完全陌生,因此我将欣赏显式代码或指向简单教程页面的链接。谢谢你。
我尝试了以下两种方法但没有成功.
第一个是级联需求文件.
# requirements.txt
-r requirements/req2.txt
-r requirements/req3.txt
Run Code Online (Sandbox Code Playgroud)
# requirements/req2.txt
Django==1.7.7
Run Code Online (Sandbox Code Playgroud)
# requirements/req3.txt
-i https://testpypi.python.org/pypi
foo-bar==0.4
Run Code Online (Sandbox Code Playgroud)
pip install -r requirements.txt导致pip没有找到Django.
第二次尝试是将两个要求都包含在一个文件中:
-i https://pypi.python.org/pypi/
Django==1.7.7
-i https://testpypi.python.org/pypi
foo-bar==0.4
Run Code Online (Sandbox Code Playgroud)
pip install -r requirements.txt导致同样的错误,pip没有找到Django.
如何使用pip从不同服务器/ index-urls安装软件包?
TL;DR即使我已经使用install_requiresin指定了依赖项setup.py,但安装还是pip失败,因为找不到某些依赖项。
我开发了一个软件包,打算通过PyPi. 我创建了一个内置的分发轮并将其上传到,testPyPI以查看上传是否一切正常以及是否可以从用户角度安装该包。
但是,当我尝试pip在普通 python 2.7 环境中安装该包时,安装过程在安装依赖项时失败。
我的包依赖于这些包(我setup.py相应地将其添加到文件中):
...
install_requires=['numpy','gdal','h5py','beautifulsoup4','requests','tables','progress'],
...
Run Code Online (Sandbox Code Playgroud)
因此,当我运行 pip install 时,一切看起来都正常,直到收到此错误:
找不到满足进度要求的版本(来自#NAME#)(来自版本:)找不到进度的匹配发行版(来自#NAME#)
当我删除进度依赖项时(没有它我也可以生活),同样的事情也会发生pytables:
找不到满足要求的版本表(来自#NAME#)(来自版本:)找不到表的匹配分布(来自#NAME#)
如果我事先手动运行pip install tables,pip install progress一切都会按预期进行。
那么,我如何确保如果有人下载我的软件包,所有缺少的依赖项都会随之安装?
相关奖金问题:
MANIFEST.in如果模块不可用,我可以在包中包含一个wheel文件(也许通过)并将其安装为依赖项吗?如果是这样,怎么办?
我正在使用SetupTools 构建我自己的包。在 INSTALL_REQUIRES 中setup.py我有以下依赖项:
...
INSTALL_REQUIRES = [
'ray>=0.8.7',
'pyyaml>=5.3',
]
setup(name=PACKAGE_NAME,
version=VERSION,
description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
long_description_content_type=LONG_DESC_TYPE,
author=AUTHOR,
license=LICENSE,
author_email=AUTHOR_EMAIL,
url=URL,
install_requires=INSTALL_REQUIRES,
packages=find_packages()
)
Run Code Online (Sandbox Code Playgroud)
当我运行时pip3 install -i https://test.pypi.org/simple/ r3po==0.0.6,出现以下错误:
ERROR: Could not find a version that satisfies the requirement pyyaml>=5.3 (from r3po==0.0.6) (from versions: 3.11)
ERROR: No matching distribution found for pyyaml>=5.3 (from r3po==0.0.6)
Run Code Online (Sandbox Code Playgroud)
然而,pip3 search pyyaml它告诉我 PyYAML 肯定存在:
PyYAML (5.3.1) - YAML parser and emitter for Python
并且pip3 install pyyaml(在 …
我正在使用 pip 创建一个 PyPi 包,并尝试测试它是否在测试环境 ( https://testpypi.python.org/pypi ) 上工作。现在我有一个包似乎存在于 prod PyPi 安装中但不在测试中。如果我使用 prod PyPi 安装依赖项(即 pip install iso8601==0.1.4),它可以正常工作,但如果我从测试 PyPi 安装(即 pip install iso8601==0.1.4 -i https://testpypi. python.org/pypi ) 我明白了
Could not find a version that satisfies the requirement iso8601==0.1.4 (from versions: )
No matching distribution found for iso8601==0.1.4
Run Code Online (Sandbox Code Playgroud)
当我尝试安装我的软件包时,我遇到了同样的错误:
pip install -i https://testpypi.python.org/pypi united-states-congress
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
EDIT2:不。删除并重新创建 virtualenv 后,现在看起来麻线是问题所在。
$ mkvirtualenv congress
New python executable in /Users/bytenel/.virtualenvs/congress/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /Users/bytenel/.virtualenvs/congress/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/bytenel/.virtualenvs/congress/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/bytenel/.virtualenvs/congress/bin/preactivate
virtualenvwrapper.user_scripts creating …Run Code Online (Sandbox Code Playgroud) 我创建了一个Python包,将其上传到TestPyPI,并尝试将其安装到新的虚拟环境中。pip 无法安装所需的软件包,但如果我尝试使用 来安装相同的软件包pip install -r requirements.txt,它就可以工作。
我按照打包 Python 项目setup.py中列出的指南创建了文件。我将我的包上传到 TestPyPI 并尝试将其安装到带有和的全新虚拟环境中。Python 3.6.4pip 19.1.1
这是我的安装说明:pip install -i https://test.pypi.org/simple/ my-package-name==0.0.1
这是我的通话内容setuptools.setup(仅相关内容):
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
],
install_requires=[
"requests",
"jsonpickle",
"pandas",
"matplotlib",
"seaborn",
"Pillow"
]
Run Code Online (Sandbox Code Playgroud)
它首先成功安装 matplotlib,但后来出现以下错误:
ERROR: Could …
在一个 Python 项目中,我install_requires在我setup.py的如下使用。
install_requires=['numpy', 'scipy', 'matplotlib']
Run Code Online (Sandbox Code Playgroud)
然后我按如下方式创建源代码、二进制文件和轮子。
python setup.py sdist bdist bdist_wheel
Run Code Online (Sandbox Code Playgroud)
当我发布时,我使用twine.
twine upload --repository dist/testpypi mypackage-0.1.1-py2-none-any.whl
Run Code Online (Sandbox Code Playgroud)
在 Python 2.7 conda 环境中,然后我尝试测试安装。
pip install -i https://test.pypi.org/simple/ mypackage==0.1.1
Run Code Online (Sandbox Code Playgroud)
但是,我收到以下错误消息:
错误:找不到满足 matplotlib 要求的版本(来自 mypackage)(来自版本:无) 错误:找不到 matplotlib 的匹配发行版(来自 mypackage)
当我做 a pip listand 时conda list,确实没有matplotlib列出包。
我究竟做错了什么?我认为(这一点是我的理解崩溃的地方)install_requires会列出先决条件,并pip install会选择并自动安装要求?但是,install_requires如果尚未安装其声明的依赖项,它似乎可以防止安装包。
在某些 Internet 搜索中,他们似乎建议我包含一个requirements.txtvia MANIFEST.in(例如include requirements.txt),然后pip install将自动安装依赖项。但是,在尝试该方法后,我仍然收到相同的错误消息。我尝试requirements.txt如下。
matplotlib
Run Code Online (Sandbox Code Playgroud)
还有如下。
matplotlib>=2.2.3 …Run Code Online (Sandbox Code Playgroud) 我已经完成了这个小包,我想在我的社区中分发。它现在在 test.pypi 上,当我想尝试安装它时,它给出了找不到依赖项的错误。
设置文件
...
install_requires=[
'defcon>=0.6.0',
'fonttools>=3.31.0'
]
...
Run Code Online (Sandbox Code Playgroud)
抛出这个错误
ERROR: Could not find a version that satisfies the requirement defcon>=0.6.0 (from sameWidther==0.6) (from versions: none)
ERROR: No matching distribution found for defcon>=0.6.0 (from sameWidther==0.6)
Run Code Online (Sandbox Code Playgroud)
但是当我手动安装时,它可以工作
pip install 'fonttools>=3.6.0'
pip install 'defcon>=0.6.0'
Run Code Online (Sandbox Code Playgroud) 我有一个包已经上传到test.pypi.
我可以在我的机器上的虚拟环境中安装此软件包,而不会出现任何问题
pip install --index-url https://test.pypi.org/simple/ package_name_here
Run Code Online (Sandbox Code Playgroud)
在'requirements.txt'文件中有一个包的要求列表,这些要求也包含在setup.py中的setup dict中的'install_requires'中.
这在我的机器上工作正常.当我在我的一个组本地服务器上的干净虚拟环境中尝试相同的进程时,我收到以下错误:
Could not find a version that satisfies the requirement widgetsnbextension>=3.2.1 (from package_name_here) (from versions: )
No matching distribution found for widgetsnbextension>=3.2.1 (from package_name_here)
Run Code Online (Sandbox Code Playgroud)
对于requirements.txt文件中的许多要求.
但是当安装失败时,如果我这样做:
pip install widgetsnbextension
Run Code Online (Sandbox Code Playgroud)
pip发现并安装widgetsnbextension-3.2.1没有任何问题.
requirements.txt文件是使用pip冻结制作的,所以我很困惑为什么它可以在没有版本号的情况下工作,但不能使用它.
谁能解释一下我做错了什么?
python ×10
pip ×8
pypi ×5
python-3.x ×2
setup.py ×2
matplotlib ×1
package ×1
packaging ×1
python-2.7 ×1
pyyaml ×1
scikit-learn ×1
setuptools ×1