0
4

More than 3 years have passed since last update.

Windows10でpoetry

Last updated at Posted at 2021-02-14

Pythonのパッケージ管理はpoetryが便利です。
poetry installですぐに環境を再現できます。
pipを利用するためpyenvとの相性がいいです。
そんなpoetryをWindows10でも使うための方法です。
(公式にもあるので新しい情報はないです。)

インストールのコマンドまとめ

サクッとインストールしたい人はこちらを参照してください。

# powershell
python -V
(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py -UseBasicParsing).Content | python -
poetry --version
poetry config virtualenvs.in-project true

インストール方法

前提条件

Pythonがpowershellで使えること。
具体的には次のコマンドでバージョンが確認できること。(3.xを推奨します。)

python -V

poetry

基本的には公式に従います。
公式にあるようにpipでのインストールは推奨しません。
(poetryのパッケージ管理にpoetryが含まれてしまうため。)

poetry:https://python-poetry.org/docs/

powershellで以下のコマンドを実行すれば、ほぼ終了です。

# powershell
(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py -UseBasicParsing).Content | python -
exit

一度powershellを終了し、以下のコマンドでpoetryがインストールしていることを確認します。

poetry --version

もしうまくインストールされていないようであれば、
アンインストールして環境を確認してみましょう。
アンインストールは--uninstallを付けるだけです。
参考:https://qiita.com/makuramoto1/items/b3f4a0d610e4f97ef3f8

(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py -UseBasicParsing).Content | python - --uninstall

最後に、プロジェクト内に仮想環境を作成するように設定することをお勧めします。
これを実行しておくとプロジェクトのルートに.venvが作られるようになります。

poetry config virtualenvs.in-project true

ちょっと使ってみる

# 新しくプロジェクトを作る(ディレクトリが作成されます)
poetry new

# 新しくパッケージ管理を行う(tomlファイルができます)
poetry init

# すでに管理されているプロジェクトにパッケージ情報を反映(tomlをもとにインストールします)
poetry install

# パッケージを追加(tomlファイルも更新されます)
poetry add [module]

まとめ

まとめるほど内容はないですが、poetryは1行で導入できます。
Pythonの環境はpyenv-winで導入するといいと思います。
シンボリックリンクとか自分で張ったりするのは大変なので。

0
4
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
4