我最近弄了一个项目,想打包上传到pypi,根据李辉老师书籍的相关章节《15.6.3 为打包做准备》进行了配置,使用md长描述(long_description)。却发现上传到pypi后,该项目描述无法正确显示。
刚刚再使用testpypi
进行上传调试,会报400错误,说使用了默认的reStructuredText
格式而没有使用md格式。之前的上传也是有报这个错误。
> python setup.py sdist bdist_wheel
...
> twine upload --repository testpypi .\dist\celery_sqlalchemy_scheduler-0.2.0.dev0.tar.gz
Enter your username:
Enter your password:
Uploading distributions to https://test.pypi.org/legacy/
Uploading celery_sqlalchemy_scheduler-0.2.0.dev0.tar.gz
32%|████████████████████████ | 8.00k/24.6k
100%|████████████████████████████████████████████████████████
██████████████████| 24.6k/24.6k [00:01<00:00, 14.5kB/s]
NOTE: Try --verbose to see response content.
HTTPError: 400 Client Error: The description failed to render in the default format of reStructuredText. See https://test.pypi.org/help/#description-content-type for more information. for url: https://test.pypi.org/legacy/
可是我觉得我setup.py
配置应该没有问题,相关配置代码如下:
from os import path
from codecs import open
try:
from setuptools import find_packages, setup
except ImportError:
from distutils.core import setup, find_packages
# To use a consistent encoding
basedir = path.abspath(path.dirname(__file__))
# Get the long description from the README file
with open(path.join(basedir, 'README.md'), encoding='utf-8') as f:
long_description = f.read()
setup(
...
long_description=long_description,
long_description_content_type="text/markdown", # 长描述内容类型
...
可在 这里 查看setup.py
的完整配置。