1

我正在使用 ubuntu,我已经创建了一个 python 包,它已准备好在 PyPI 上注册,但是当我使用python setup.py register它时显示如下错误:

Server response (410): This API is no longer supported, instead simply upload the file.

我知道这是找不到 .pypirc 文件的错误,但我不知道如何解决这个问题,因为我家没有 .pypirc 文件。我们不能只创建 pypirc 文件吗?(只是问)。当我在 virtualenv 中使用 register 命令时,还有一个不同的错误,我得到这个:

Server response (410): Gone (This API has been deprecated and removed from legacy PyPI in favor of using the APIs available in the new PyPI.org implementation of PyPI (located at https://pypi.org/). For more information about migrating your use of this API to PyPI.org, please see https://packaging.python.org/guides/migrating-to-pypi-org/#uploading. For more information about the sunsetting of this API, please see https://mail.python.org/pipermail/distutils-sig/2017-June/030766.html)

这是我的 setup.py 文件

from setuptools import setup

setup(name='Utilitarian',
      version='0.1',
      description='little description',
      url='https://github.com/Shivams334/Utilitarian.git',
      author='Shivam Sharma',
      author_email='shivams334@gmail.com',
      license='MIT',
      packages=['Utilitarian'],
      zip_safe=False)

请帮忙。谢谢你。

4

1 回答 1

6

您需要.pypirc自己在HOME目录中创建文件

touch ~/.pypirc

该文件应包含以下代码,将您的登录名和密码输入pypi

[distutils]
index-servers =
    pypi
    pypitest

[pypitest]
repository = https://test.pypi.org/legacy/
username = <your username>
password = <your password>

[pypi]
repository = https://upload.pypi.org/legacy/
username = <your username>
password = <your password>

因为您将登录名和密码放入此文件,您可能希望更改它的权限,以便只有您可以读取和写入它。

chmod 600 ~/.pypirc

之后你可以尝试注册你的包,顺便说一下,我强烈建议你使用twine库来加载你的包,只需安装它

pip install twine

然后为您的包进行分发

python setup.py install

此命令将创建一个dist包含您的模块的文件夹,然后注册您的项目(如有必要):

twine register dist/example-project-x.y.z.tar.gz

之后,您可以使用以下命令将您的包上传到 pip

twine upload dist/*
于 2017-07-03T19:07:28.247 回答