LoginSignup
0
0

More than 3 years have passed since last update.

Python パッケージをローカルから PyPI にアップロードするときの設定

Posted at

現在は CI/CD の一環で GitHub Actions にデプロイメントを設定するのが
ベストプラクティスと思われます。

こちらの方法はテストやトラブルの回避策としてメモを残しています。

手順

1.
.pypirc (PyPi のアカウント設定ファイル) を ~/ に配置します。
内容は以下の通りです:

[pypirc]
servers =
    pypi
    testpypi
[pypi]
repository: https://upload.pypi.org/legacy/
username: __token__
password: (API token)
[testpypi]
repository: https://test.pypi.org/legacy/
username: __token__
password: (API token)

※ (API token) を PyPI と Test PyPI それぞれで発行した API token に置き換えましょう。

2.
Twine がインストールされた仮想環境の中で以下のコマンドを実行します。

twine upload --repository pypi dist/*

参考: Uploading the distribution archives | Packaging Python Projects — Python Packaging User Guide

Pipenv のショートカットに登録する場合

Pipfile に以下のように登録しておくと便利です。

[scripts]
clear = "rm -rf yamldataclassconfig.egg-info/* build/* dist/*"
build = "python setup.py sdist bdist_wheel"
deploy = "twine upload --repository pypi dist/*"

そして、以下のようにコマンドを実行します。

pipenv run clear
pipenv run build
pipenv run deploy
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0