11
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Pythonのライブラリ依存関係で溺死しかけたのでvenvを覚えた

Last updated at Posted at 2025-03-04

はじめに

別に新規性のある話ではない
備忘です

雑にpip installしていく→絶望

初心者あるあるですが言われた通りライブラリをいれます、を続けていくと複数のプロジェクトだとか歴史的な問題だとかanacondaいれてたりでライブラリがぐずぐずになります
個人的にはstreamlitにdeployしたときに膨大なrequirements.txtになり、deployに失敗して絶望した

あなたの今日やるべきこと→venv

python -m venv [dir]
cd dir
./bin/activate

dirの下に環境をつくってくれるぜ

how to use

aliasをつくる

.zshrc (など)

alias py=$HOME/venv/bin/python

home dir直下にvenvつくった場合。そこは適当に読みかえしてください

pip installする

py -m pip install [hoge]

-mつけてやる
別にpipをaliasにしてもいいんだけど

おためし

!py -m pip install langchain-openai memento slack_bolt
[いっぱいインストール]
!py -m pip freeze
aiohappyeyeballs==2.4.6
aiohttp==3.11.13
aiosignal==1.3.2
annotated-types==0.7.0
anyio==4.8.0
attrs==25.1.0
certifi==2025.1.31
charset-normalizer==3.4.1
...
pip3 freeze
packaging==24.2
wheel @ file:///opt/homebrew/Cellar/python%403.13/3.13.2/libexec/wheel-0.45.1-py3-none-any.whl#sha256=b9235939e2096903717cb6bfc132267f8a7e46deb2ec3ef9c5e234ea301795d0

かくして環境はわけられた

まとめ

pythonでも環境はわけられる。もちろん他の言語の環境設計のが良好なのは多いが、それでも環境がわけられるのだからありがたい

しかし

ここまでやったあげくpipenvだとかryeを知る
ほんとにな

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?