How am I supposed to register a package to PyPI?

会有一股神秘感。 提交于 2019-12-10 02:15:52

问题


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

  1. Create a valid project, especially setup.py
  2. python setup.py sdist bdist_wheel
  3. Make sure you have a correct ~/.pypirc with your credentials from https://pypi.python.org/pypi
  4. 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:

  1. Create a valid setup.py for your project.
  2. Create wheel and dist:

    python setup.py sdist bdist_wheel
    
  3. To avoid having to re-enter your password you can populate ~/.pypirc with your credentials from pypi.

  4. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!