0

I have created a package and tried to upload it to testpypi to test it, as suggested in the Python Packaging User Guide. I created a distribution, registered it, and uploaded it to 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

This worked fine, but trying to install it

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

fails with the following error:

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'"
nalzok
  • 14,965
  • 21
  • 72
  • 139
m00am
  • 5,910
  • 11
  • 53
  • 69

1 Answers1

0

What is going on

The command line parameters for to use the testpypi server are not the same for upload and installation. For pip, the -r parameter specifies a requirements file, which apparently can be a URL. If you add a -v you get:

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"?>'
[...]

The response from https://testpypi.python.org/pypi however is not a valid requirements-file and pip crashes.

How to fix this

To install from another source than pypi using pip install, you need to use the -i parameter:

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

This should work as expected and install mypackage from the testpypi server.

m00am
  • 5,910
  • 11
  • 53
  • 69