#author("2020-05-29T18:57:02+09:00","default:dex","dex") #author("2024-09-11T13:57:13+09:00","default:dex","dex") #contents * pip: パッケージ管理 [#la52ff6c] ---- ** 依存関係の表示 [#p4cfc594] - python 2/3混在環境ではmoduleを指定して実行 #geshi(bash){{ # python2 python -m pipdeptree # python3 python3 -m pipdeptree }} - インストール #geshi(bash){{ sudo pip install pipdeptree }} - ただ、requestsのように内部で他のmoduleに依存していても、表示されないものもあった。 #geshi(bash){{ pipdeptree ansible==2.9.6 - cryptography [required: Any, installed: 2.8] - cffi [required: >=1.8,!=1.11.3, installed: 1.14.0] - pycparser [required: Any, installed: 2.20] - enum34 [required: Any, installed: 1.1.10] - ipaddress [required: Any, installed: 1.0.23] - six [required: >=1.4.1, installed: 1.14.0] - jinja2 [required: Any, installed: 2.11.1] - MarkupSafe [required: >=0.23, installed: 1.1.1] - PyYAML [required: Any, installed: 5.3.1] ... }} ---- ** コマンドの外部公開 [#kcb66f8c] - GitHubで公開 -- pipでインストールできる #geshi(bash){{ pip install git+https://github.com/<user>/<project> }} - https://pypi.org/ で公開 - 記事 -- [[Pythonで作ったコマンドをGitHub経由でpipインストール可能にする | Developers.IO:https://dev.classmethod.jp/server-side/python/pip-install-via-github-command/]] ---- ** wheel: パッケージの固定化 [#dd474988] - 記事 -- [[インターネットと疎通がないマシンに Python パッケージをインストールする - CUBE SUGAR CONTAINER:https://blog.amedama.jp/entry/2015/09/16/214543]] -- [[pipとwheelでテスト環境構築をスピードアップ:http://pelican.aodag.jp/20140502-pip-wheel-speedup.html]] ---- ** pipenv: [#f67e440f] - [[pypa/pipenv: Python Development Workflow for Humans.:https://github.com/pypa/pipenv]] -- pipとvirtualenvを一緒に管理してくれる。 - プロジェクトディレクトリに .venv ディレクトリを作る #geshi(bash){{ export PIPENV_VENV_IN_PROJECT=true }} - 記事 -- [[Pipfile.lockで固定された依存関係を再現するならpipenv syncコマンドを使おう | Developers.IO:https://dev.classmethod.jp/articles/pipenv-sync-is-useful/]] -- [[【小ネタ】Lambda Layersのパッケージ作成に便利!!pipenvでsync対象ディレクトリを指定する方法 | DevelopersIO:https://dev.classmethod.jp/server-side/python/pipenv-sync-target-dir/]] -- [[[Python] Pipenvで仮想環境をプロジェクトディレクトリ配下に作る方法 | DevelopersIO:https://dev.classmethod.jp/server-side/python/pipenv-venv-setting/]] -- [[Pipenvを使ったPython開発まとめ - Qiita:https://qiita.com/y-tsutsu/items/54c10e0b2c6b565c887a]] ---- **pipでミラーを指定する [#t233acad] - コマンド単位で指定 #geshi(bash){{ sudo pip install requests==2.5.3 --index-url http://pypi.example.com/simple/ --trusted-host pypi.example.com }} - ユーザ単位で指定 #geshi(bash){{ mkdir ~/.pip vi ~/.pip/pip.conf ---- [global] index-url = http://pypi.example.com/simple/ [install] trusted-host = pypi.example.com ---- }} - ホスト単位で指定: /etc/pip.conf