我应该如何向PyPI注册包?

2024-05-16 02:57:32 发布

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

packaging and distributing Python packages的文档中,它说要将twine.pypirc中的repository = https://upload.pypi.org/legacy/一起使用。现在,这个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工具来注册?在


Tags: httpsorgpypinone方式py3legacyany
3条回答

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

TL;DR

  1. 创建一个有效的项目,尤其是setup.py
  2. python setup.py sdist bdist_wheel
  3. 请确保您有一个正确的~/.pypirc以及来自{a2}的凭据
  4. twine upload dist/*-不再需要/不可能注册

我的.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]

下面的马丁托马的答案现在似乎被否决了(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.

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

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

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

接下来,请执行以下步骤:

  1. 为您的项目创建一个有效的setup.py。在
  2. 创建车轮和距离:

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

  4. 现在upload命令负责注册,因此命令现在是:

    ^{3美元

使用这个存储库URL,它将工作repository = https://upload.pypi.org/legacy/。在

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

相关问题 更多 >