エンジニアリングとお金の話

都内で働くエンジニアの日記です。

共通的に使用するpythonコマンドはpipxで管理することにした

【SPONSORED LINK】

pythonで環境を構築する際に常に悩んでいたのが、共通的に使用したいpythonコマンドのインストール方法である。具体的にはPoetryやJuypter labなど。 今まではpyenvでインストールしたpython環境にpipで導入していたが、なんか気持ち悪い。良い解決方法が無いか探していたらpipxなるものを見つけた。

github.com

pipxを使用すると共通的に使用したいpythonコマンド毎に仮想環境を構築してインストールを行う。これでpyenvでインストールした環境をクリーンに保つことができる。

install方法は以下の通り

brew install pipx
pipx ensurepath

使用方法は以下の通り

# インストール
pipx install poetry

# インストールリスト表示
pipx list

# インストール資産アップデート
pipx upgrade poetry

#インストール資産削除
pipx uninstall poetry

インストールした資産は以下の通り

package jupyter 1.0.0, installed using Python 3.12.1
 - ipython
 - ipython3
 - jlpm
 - jsonpointer
 - jsonschema
 - jupyter
 - jupyter-console
 - jupyter-dejavu
 - jupyter-events
 - jupyter-execute
 - jupyter-kernel
 - jupyter-kernelspec
 - jupyter-lab
 - jupyter-labextension
 - jupyter-labhub
 - jupyter-migrate
 - jupyter-nbconvert
 - jupyter-notebook
 - jupyter-qtconsole
 - jupyter-run
 - jupyter-server
 - jupyter-troubleshoot
 - jupyter-trust
 - normalizer
 - pybabel
 - pygmentize
 - pyjson5
 - qtpy
 - send2trash
 - wsdump
 - man1/ipython.1
package poetry 1.7.1, installed using Python 3.12.1
 - poetry
package powerline-shell 0.7.0, installed using Python 3.12.1
 - powerline-shell
package python-dotenv 1.0.1, installed using Python 3.12.1
 - dotenv

注意点としてpipxでjupyterをインストールする時は--include-depsを付ける必要がある。

pipx install --include-deps jupyter

※参考URL

Pythonの便利ツールpipx

MacにPythonの環境構築をするお話 2020年版 | gadgetlunatic