LoginSignup
1
1

PoetryとPyenvでPythonのバージョン管理

Last updated at Posted at 2023-09-16

はじめに

PoetryとPyenvでプロジェクトを作成しようとしたら躓いたのでメモ代わりに投稿する。

pyenv global を用いる場合

pyenvで指定しているデフォルトのバージョンを用いる時は何も考えずにPoetryのコマンドを叩く。

poetry init 
poetry install

pyenv local を用いる場合

デフォルト (global) とは異なるバージョンを指定 (pyenv local) して、Poetryプロジェクトを作りたい時はひと手間必要である。
先の場合と同じコマンドを叩くと以下のようなエラーが出る。
The currently activated Python version 3.10.9 is not supported by the project (^3.80). Trying to find and use a compatible version.

この場合は先に仮想環境を作成してからPoetryプロジェクトを作成する。

pyenv local [指定したいバージョン]
python -m venv .venv
poetry init
poetry install

厳密にはpoetry initの実行は仮想環境を作成する前でも構わない。

1
1
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
1
1