LoginSignup
1
0

Python環境構築覚書 (asdf, poetry)

Last updated at Posted at 2024-02-11

この記事はなに?

Python環境構築について、  
気がつくと月に数回調べているので、自分用の覚書として書く。

環境のセットアップ

今回は以下の環境を使っています。

なお、poetry、Pythonともにasdfからインストールできます。

ここでは、asdfがインストールされている前提で、Python、Poetryのインストールから説明します。

Pythonインストール(asdfから)

基本的には以下のサイトの手順でOKです。
https://dev.classmethod.jp/articles/asdf-python-introduction/

# Python のプラグインとリポジトリを確認します
% asdf plugin list all | grep python
(出力↓)
python                       *https://github.com/danhper/asdf-python.git

# プラグインをインストールします。
% asdf plugin add python https://github.com/danhper/asdf-python.git

# プラグインがインストールできたか確認します。
% asdf plugin list
(出力↓)
python

# インストール可能なバージョン一覧を確認
% asdf list all python
(出力↓)
ズラズラと出てきます。

# 今回はPython3.11.6をローカルにインストールします。
# メモ:chromadbとの相性により3.12にできない。
% asdf install python 3.11.6
% asdf local python 3.11.6
% python --version
(出力↓)
Python 3.11.6

poetryインストール(asdfから)

poetryのインストールもPythonと基本的な手順は一緒です。


% asdf plugin-add poetry
% asdf list-all poetry
(出力↓)
(中略)
1.7.1
% asdf install poetry 1.7.1
% asdf local poetry 1.7.1
% poetry --version
(出力↓)
Poetry (version 1.7.1)

poetryのプロジェクト初期化


# poetry初期化(基本的に全部デフォルトで良い)
% poetry init

# 仮想環境の使用
% poetry config virtualenvs.in-project true --local

# pythonバージョン確認
% poetry run python --version
% poetry env list

requirements.txtから依存パッケージをインストールする

cat requirements.txt | xargs poetry add
1
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
1
0