如何發佈你的套件到 PyPI

網路上的文章都寫的滿簡單的,

先在 PyPI 建帳號:
https://pypi.org/account/register/

我是看這篇教學: PYTHON3 打包上传PYPI失败及解决方法
https://www.cnblogs.com/myworldfordata/p/17872738.html

安裝 twine相關工具

python -m pip install build
python -m pip install twine
python -m pip install wheel

打包 setup.py:

python setup.py sdist bdist_wheel

上傳:

python -m twine upload dist/*

打包的步驟會產生出3個新的資料夾, build/, dist/ 還有 .egg 的, 如果用不到的話, 記得刪除。


下面是”錯誤參數”的示範:

使用帳/密上傳到 PyPI 已失效, 要使用 token:
https://pypi.org/help/#apitoken

Using this token

To use this API token:

  • Set your username to __token__
  • Set your password to the token value, including the pypi- prefix

For example, if you are using Twine to upload your projects to PyPI, set up your $HOME/.pypirc file like this:

[pypi]
  username = __token__
  password = pypi-xxxxxx

$HOME/.pypirc, 在 Windows 路徑可能是, C:\Users\YourName\.pypirc

To use an API token:

  • Set your username to __token__

千萬別吧 username 真的打入 username , 不然會顯示錯誤訊息:

INFO     Response from https://upload.pypi.org/legacy/:
         403 Invalid or non-existent authentication information. See https://pypi.org/help/#invalid-auth for
         more information.
INFO     <html>
          <head>
           <title>403 Invalid or non-existent authentication information. See
         https://pypi.org/help/#invalid-auth for more information.</title>
          </head>
          <body>
           <h1>403 Invalid or non-existent authentication information. See https://pypi.org/help/#invalid-auth
         for more information.</h1>
           Access was denied to this resource.<br/><br/>



          </body>
         </html>
ERROR    HTTPError: 403 Forbidden from https://upload.pypi.org/legacy/
         Invalid or non-existent authentication information. See https://pypi.org/help/#invalid-auth for more
         information.

使用

username = __token__

之後就會成功上傳:

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *