我正在尝试将我的包上传到PyPI上,但无法正常工作。 PyPi
或setuptools
似乎在我的版本名称前后添加了-
。最初,我具有以下版本:ß-2018.8
,但我认为unicode字符不起作用。然后,我将其移至beta-2018.8
,但这也不起作用。我什至尝试了基本的2018.8
,但仍然遇到相同的错误?!
有人可以帮我弄清楚发生了什么吗?
我的点子版本:
pip 18.0 from /Users/mu/anaconda/envs/py3_clone/lib/python3.6/site-packages/pip (python 3.6)
我的命令:
python setup.py register sdist upload
我的错误:
Submitting dist/thisismypackagename--2018.08-.tar.gz to
https://upload.pypi.org/legacy/
Upload failed (400): '-2018.08-' is an invalid value for Version. Error: Start and end with a letter or numeral containing only ASCII numeric and '.', '_' and '-'. See https://packaging.python.org/specifications/core-metadata
error: Upload failed (400): '-2018.08-' is an invalid value for Version. Error: Start and end with a letter or numeral containing only ASCII numeric and '.', '_' and '-'. See https://packaging.python.org/specifications/core-metadata
我的__init__.py
:
# =======
# Version
# =======
__version__="beta-2018.08"
我的setup.py
import re
from setuptools import setup
# Version
version = None
with open("./thisismypackagename/__init__.py", "r") as f:
for line in f.readlines():
line = line.strip()
if line.startswith("__version__"):
version = line.split("=")[-1].strip()
setup(name='thisismypackagename',
version=version,
description='package description',
author='Josh L. Espinoza',
packages=["thisismypackagename"],
zip_safe=False)
这是我的目录结构:
thisismypackagename
| thisismypackagename
| thisismypackagename | __init__.py
| setup.py
答案 0 :(得分:3)
这是因为版本周围的双引号是
version = None
with open("./thisismypackagename/__init__.py", "r") as f:
for line in f.readlines():
line = line.strip()
if line.startswith("__version__"):
version = line.split("=")[-1].strip()
print version
# "beta-2018.08"
PyPI将双引号替换为破折号。消除双引号并解决问题:
version = line.split("=")[-1].strip().strip('"')