1.注册一个pypi账号,注册完成后需要邮箱认证,以及Two factor authentication (2FA)认证,选择第一个,
然后进入到TOTP验证,使用任何一种TOTP验证码生成器或者程序代码,生成验证码,然后输入验证。
通过后,在账户设置里面,设置api token,添加一个,然后复制token码(这个token码只会出现一次,一定要记住或保存!!!不然要重新创!)。
2.构建要上传的项目:里面可以为pyd/py文件,具体参考
https://blog.youkuaiyun.com/yifengchaoran/article/details/113447773
3.构建好项目后,cd至项目setup.py同级目录下,使用命令行
python setup.py sdist bdist_wheel
构建项目,
然后继续使用命令行,前提是安装了twine(pip install twine)
twine upload dist/*
然后会提示输入api token,把上面拿到的token码粘贴进去,回车上传
至此,上传成功后就可以了。其他用户可以通过pip install 包名 来安装了。
注:如果上传报错(netpin2***el为我自己写的包名字):
WARNING Error during upload. Retry with the --verbose option for more details.
ERROR HTTPError: 400 Bad Request from https://upload.pypi.org/legacy/
File already exists ('netpin2***el-0.1.2-py3-none-any.whl', with blake2_256 hash 'e4e465afa1e8b26a1da183760ab526e7b45016776120fa7a51c145bf1518dd07').
See https://pypi.org/help/#file-name-reuse for more information.
那就是文件已经在了,理解为版本已经在了,做法是在setup.py里的version="x.x.x",改成新的版本号。