我怎么能把包注册到PyPI?

时间:2016-10-13 13:41:45

标签: python pypi

packaging and distributing Python packages的文档中,它表示在twine中使用repository = https://upload.pypi.org/legacy/.pypirc。现在这个URL - 从它的最后一点 - 是一种传统的做事方式,以及一个不存在的方式:

$ 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/

现在使用scriptdoctest.egg-info/PKG-INFO是注册包的首选和唯一方法,还是有其他方法可以使用twine或其他一些CLI工具执行此操作?

3 个答案:

答案 0 :(得分:6)

shttps://packaging.python.org/distributing/实际上提供了所有必要的信息。

TL; DR

  1. 创建有效项目,尤其是setup.py
  2. python setup.py sdist bdist_wheel
  3. 请确保您使用https://pypi.python.org/pypi
  4. 的凭据获得正确的~/.pypirc
  5. twine upload dist/* - 不再需要/可能注册
  6. 我的.pypirc如下所示:

    [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]
    

答案 1 :(得分:3)

使用此存储库网址,它将有效repository = https://upload.pypi.org/legacy/

我想文档有点过时了,因为包装搬到仓库已经发生了很多事情:https://pypi.org/

答案 2 :(得分:3)

马丁托马的回答现在似乎已被弃用(here)。

  

建议使用新网址“https://upload.pypi.org/legacy/”   或者保留未指定的URL并允许麻线选择。

因此,您的.pypirc应如下所示:

[pypi]
username=[your username]
password=[your password]

[pypitest]
username=[your username]
password=[your password]

接下来按照以下步骤操作:

  1. 为您的项目创建有效的setup.py
  2. 创建wheel and dist:

    python setup.py sdist bdist_wheel
    
  3. 为避免重新输入密码,您可以使用您的凭据填充~/.pypirc pypi

  4. 现在upload命令负责注册,所以命令现在是:

    twine upload dist/*
    
相关问题