Python - 无法将模块发布到 PyPI

Python - Cannot publish module to PyPI

我的问题是无法将我的模块上传到 PyPI。当我 运行 twine upload dist/easy-email-0.0.1.tar.gz 我得到 HTTPError: 400 Client Error: 'Easy-email-0.0.1.tar.gz' is an invalid value for Download-URL. Error: Invalid URI see https://packaging.python.org/specifications/core-metadata for url: https://test.pypi.org/legacy/

我做错了什么?

这是 setup.py:

from distutils.core import setup

setup(
    name = 'easy-email',
    packages = ['easy-email'],
    version = '0.0.1',  # Ideally should be same as your GitHub release tag varsion
    description = 'Send emails in python!',
    author = 'myname',
    author_email = 'myemail',
    url = 'https://github.com/marmadukeandbob05/Easy-Email/',
    download_url = 'Easy-Email-0.0.1.tar.gz',
    keywords = ['email', 'gmail'],
    classifiers = [],
)

您的 download_url 无效,它不是有效的 URL。请注意,在将安装存档上传到 PyPI 时,您根本不需要设置该值 ,因为下载 URL 是 on PyPI.

仅当您要在 其他地方 托管您的包时才设置 download_url,而不是在 PyPI 上。您必须使用完整的 URL,因此以 http://https:// 开头的 pipeasy_install 将紧跟 URL 从 PyPI 中找到安装存档。您将只使用 twine register 来注册元数据,根本不使用 twine upload

错误消息将您链接到 documentation for the field:

A string containing the URL from which this version of the distribution can be downloaded.

大胆强调我的; Easy-Email-0.0.1.tar.gz 不是 URL。它只是一个文件名。

当您希望人们从不同的主机(例如 GitHub)下载档案时,您可以使用它。例如,如果 requests project 希望人们从 GitHub 而不是从 PyPI 服务器下载版本,他们可以使用 download_url = 'https://github.com/requests/requests/archive/v2.18.4.tar.gz',然后只使用 twine register 来放置PyPI 上的元数据。