LoginSignup
4
6

More than 3 years have passed since last update.

PycharmのProject:Interpreterで、PoetryのPythonを指定する

Posted at

Poetry

Poetryはpythonのモジュール/パッケージ管理ツールです.
最近 pipenv の代わりに使い始めました.
参考)https://org-technology.com/posts/python-poetry.html

普段手元でサクッとコードを書くぶんには、特段Poetryの便利さは体感できてないです(pipenvとそんなに変わらない)
パッケージ配布とかをするのであれば、恩恵があるのかなと思っています.

Poetryのインストール先

Poetryの設定やコマンドからpythonのインストール先がサクッとわかるのかなと思ったら、少し探したので覚書き的に書いておきます.
私の場合、以下のpathでインストールされていました.

ls ~/Library/Caches/pypoetry/virtualenvs/dev-py3.6/bin/python

dev-py3.6 の部分はインストールしたpythonのバージョンによって異なるはずです.

こちらのパスを Pycharmの Project:Interpreter に設定しましょう.

Pycharmの設定

Pycharmでは御存知の通り Project:Interpreter の設定からPythonモジュールを読み込みます.
PoetryがインストールするPythonを指定しないと、Pycharmに Unresolved Reference 'hogehoge' で怒られてしまいます.

  1. PyCharm -> Preference -> Project:Workspace -> Porject Interpreter と進みます. Preferences_と_Workspace____Workspace__-_____merpay-creditscore_features_composer_v20_dags_dag_prediction_py__Workspace_.png
  2. 右端の歯車をクリックして、 addを選択します
    Preferences_と_Workspace____Workspace__-_____merpay-creditscore_features_composer_v20_dags_dag_prediction_py__Workspace_.png

  3. Existing environmentにチェック. パスからPoetryのインストールしたPythonの選択します.
    Add_Python_Interpreter_と_Preferences.png

    Add_Python_Interpreter_と_Preferences.png

  4. OKを押してダイアログを閉じると、設定が反映されます.
    Preferences_と_Workspace____Workspace__-_____merpay-creditscore_features_composer_v20_dags_dag_prediction_py__Workspace_.png

おまけ

私のよく使うpoetryコマンド(alias)

# poetry
alias po='poetry'
alias poa='poetry add'
alias poc='poetry config'
alias por='poetry run'
alias porm='poetry remove'
alias pos='poetry show'
4
6
1

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