如何使用pythonsetup.py上传?

How do I use python setup.py upload?

我正在尝试将包上传到 PyPI - 但我似乎做不到。尝试上传失败:

C:\pphp>python setup.py upload
running upload
Password:
error: No dist file created in earlier command

但我已经创建了一个 dist 文件!

然后我发现了一个有那个问题的问题 - 接受的答案是 python setup.py sdist upload,但仍然没有用:

C:\pphp>python setup.py sdist upload
running sdist
running egg_info
writing pphp.egg-info\PKG-INFO
writing top-level names to pphp.egg-info\top_level.txt
writing dependency_links to pphp.egg-info\dependency_links.txt
reading manifest file 'pphp.egg-info\SOURCES.txt'
writing manifest file 'pphp.egg-info\SOURCES.txt'
running check
creating pphp-1.2.2a1
creating pphp-1.2.2a1\pphp.egg-info
copying files to pphp-1.2.2a1...
copying README.rst -> pphp-1.2.2a1
copying setup.py -> pphp-1.2.2a1
copying pphp.egg-info\PKG-INFO -> pphp-1.2.2a1\pphp.egg-info
copying pphp.egg-info\SOURCES.txt -> pphp-1.2.2a1\pphp.egg-info
copying pphp.egg-info\dependency_links.txt -> pphp-1.2.2a1\pphp.egg-info
copying pphp.egg-info\top_level.txt -> pphp-1.2.2a1\pphp.egg-info
Writing pphp-1.2.2a1\setup.cfg
Creating tar archive
removing 'pphp-1.2.2a1' (and everything under it)
running upload
Password: (my pypi pass)
Submitting dist\pphp-1.2.2a1.tar.gz to https://upload.pypi.org/legacy/
Upload failed (403): Invalid or non-existent authentication information.
error: Upload failed (403): Invalid or non-existent authentication information.

因为我认为这可能与未注册有关,所以我使用了 python setup.py register:

C:\pphp>python setup.py register
running register
running egg_info
writing pphp.egg-info\PKG-INFO
writing top-level names to pphp.egg-info\top_level.txt
writing dependency_links to pphp.egg-info\dependency_links.txt
reading manifest file 'pphp.egg-info\SOURCES.txt'
writing manifest file 'pphp.egg-info\SOURCES.txt'
running check
We need to know who you are, so please choose either:
 1. use your existing login,
 2. register as a new user,
 3. have the server generate a new password for you (and email it to you), or
 4. quit
Your selection [default 1]:
1
Username: (my pypi username)
Password: (password)
Registering pphp to https://upload.pypi.org/legacy/
Server response (410): Project pre-registration is no longer required or supported, so continue directly to uploading files.

因为它说"continue directly to uploading files",所以我尝试了sdist register upload

C:\pphp>python setup.py sdist register upload
running sdist
running egg_info
writing pphp.egg-info\PKG-INFO
writing top-level names to pphp.egg-info\top_level.txt
writing dependency_links to pphp.egg-info\dependency_links.txt
reading manifest file 'pphp.egg-info\SOURCES.txt'
writing manifest file 'pphp.egg-info\SOURCES.txt'
running check
creating pphp-1.2.2a1
creating pphp-1.2.2a1\pphp.egg-info
copying files to pphp-1.2.2a1...
copying README.rst -> pphp-1.2.2a1
copying setup.py -> pphp-1.2.2a1
copying pphp.egg-info\PKG-INFO -> pphp-1.2.2a1\pphp.egg-info
copying pphp.egg-info\SOURCES.txt -> pphp-1.2.2a1\pphp.egg-info
copying pphp.egg-info\dependency_links.txt -> pphp-1.2.2a1\pphp.egg-info
copying pphp.egg-info\top_level.txt -> pphp-1.2.2a1\pphp.egg-info
Writing pphp-1.2.2a1\setup.cfg
Creating tar archive
removing 'pphp-1.2.2a1' (and everything under it)
running register
We need to know who you are, so please choose either:
 1. use your existing login,
 2. register as a new user,
 3. have the server generate a new password for you (and email it to you), or
 4. quit
Your selection [default 1]:
1
Username: (username)
Password: (password)
Registering pphp to https://upload.pypi.org/legacy/
Server response (410): Project pre-registration is no longer required or supported, so continue directly to uploading files.
running upload
Password: (password)
Submitting dist\pphp-1.2.2a1.tar.gz to https://upload.pypi.org/legacy/
Upload failed (403): Invalid or non-existent authentication information.
error: Upload failed (403): Invalid or non-existent authentication information.

所以既然不再需要注册,我做错了什么 sdist upload?我应该输入我的 PyPI 密码(我正在尝试的密码)还是其他什么,或者我需要先做另一件事吗?

我改用 Linux 并且 twine 工作正常 - 一定是我在 Windows 上搞砸了。已解决!

一旦 PyPI 也迁移到 https://pypi.org from https://pypi.python.org,像这样的大多数问题也应该得到解决。