pip安装失败:无效要求:'<xml版本="1.0"编码="utf-8">'

2024-06-16 09:35:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经创建了一个包,并尝试将其上载到testpypi以测试它,如Python Packaging User Guide中所建议的那样。我创建了一个发行版,注册并上传到testpypi:

me@machine$ cd mypackage
me@machine:~/mypackage$ python setup.py sdist bdist_wheel
me@machine:~/mypackage$ twine register dist/mypackage-1.0.0-py3-none-any.whl -r https://testpypi.python.org/pypi
me@machine:~/mypackage$ twine upload dist/* -r https://testpypi.python.org/pypi

这个工作很好,但尝试安装它

^{pr2}$

失败,错误如下:

Invalid requirement: '<?xml version="1.0" encoding="utf-8"?>'
Traceback (most recent call last):
[...]
pip._vendor.pyparsing.ParseException: Expected W:(abcd...) (at char 0), (line:1, col:1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/vol/home/me/miniconda3/envs/myenv/lib/python3.5/site-packages/pip/req/req_install.py", line 82, in __init__
    req = Requirement(req)
  File "/vol/home/me/miniconda3/envs/myenv/lib/python3.5/site-packages/pip/_vendor/packaging/requirements.py", line 96, in __init__
    requirement_string[e.loc:e.loc + 8]))
pip._vendor.packaging.requirements.InvalidRequirement: Invalid requirement, parse error at "'<?xml ve'"

Tags: pippyhttpsorgpypidistlinerequirement
1条回答
网友
1楼 · 发布于 2024-06-16 09:35:46

怎么回事

用于使用testpypi服务器的命令行参数对于上载和安装是不同的。 对于pip,-r参数指定了一个需求文件,该文件显然可以是一个URL。如果您添加-v,您将得到:

me@machine:~$ pip install -v -r https://testpypi.python.org/pypi mypackage

Looking up "https://testpypi.python.org/pypi" in the cache
No cache entry available
Starting new HTTPS connection (1): testpypi.python.org
"GET /pypi HTTP/1.1" 200 23968
Updating cache with response from "https://testpypi.python.org/pypi"
Invalid requirement: '<?xml version="1.0" encoding="utf-8"?>'
[...]

但是,https://testpypi.python.org/pypi的响应不是有效的需求文件,pip崩溃。在

如何修复

要使用pip install从pypi以外的其他源安装,需要使用-i参数:

^{pr2}$

这应该如预期的那样工作,并从testpypi服务器安装mypackage。在

相关问题 更多 >