问题
In the documentation for packaging and distributing Python packages, it says to use twine with repository = https://upload.pypi.org/legacy/ in .pypirc. Now this URL is both – from the last bit of it – a legacy way to do things, and a non-existing one at that:
$ twine register dist/scriptdoctest-0.1-py2.py3-none-any.whl
Registering package to https://upload.pypi.org/legacy/
Enter your username: MyUserName
Enter your password:
Registering scriptdoctest-0.1-py2.py3-none-any.whl
HTTPError: 410 Client Error: This API is no longer supported, instead simply upload the file. for url: https://upload.pypi.org/legacy/
Is using scriptdoctest.egg-info/PKG-INFO now the preferred and only way to register a package, or is there some other way to do this with twine or some other CLI tool?
回答1:
shttps://packaging.python.org/distributing/ actually provides all necessary information.
TL;DR
- Create a valid project, especially
setup.py python setup.py sdist bdist_wheel- Make sure you have a correct
~/.pypircwith your credentials from https://pypi.python.org/pypi twine upload dist/*- it is no longer necessary/possible to register
My .pypirc looks as follows:
[distutils]
index-servers =
pypi
pypitest
[pypi]
repository=https://pypi.python.org/pypi
username=Martin.Thoma
password=[your password]
[pypitest]
repository=https://testpypi.python.org/pypi
username=Martin.Thoma
password=[your password]
回答2:
Following Martin Thoma answer seem to be deprecated now (here).
It's recommended to use the new URL "https://upload.pypi.org/legacy/" or to leave the URL unspecified and allow twine to choose.
So your .pypirc should looks as follow:
[pypi]
username=[your username]
password=[your password]
[pypitest]
username=[your username]
password=[your password]
Next follow those steps:
- Create a valid
setup.pyfor your project. Create wheel and dist:
python setup.py sdist bdist_wheelTo avoid having to re-enter your password you can populate
~/.pypircwith your credentials from pypi.Now the upload command takes care of registering, so the command is now:
twine upload dist/*
回答3:
Use this repository URL, and it will work repository = https://upload.pypi.org/legacy/.
I guess documentation is a bit out of date since a lot has been happening with packaging including the move to warehouse: https://pypi.org/
来源:https://stackoverflow.com/questions/40022710/how-am-i-supposed-to-register-a-package-to-pypi