0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

venvアンチのためのpythonバージョン管理

Posted at

venvをつくりまくるとそのたびにディスクが圧迫されるのであんま好きじゃない。
僕は環境が汚れてもいい(パッケージごとの厳しいバージョン管理を必要としているほうが悪いと思ってる)ので、グローバルpythonにどんどんいろんなパッケージをぶち込んで使っている。
でもここで問題になるのがそもそもpython3.xxでないと動かないけど自分のパソコンに入っていないとき、異なるバージョンのpythonのインストールの必要が生じる。

インスコ

pipは普通要るのでチェック、それ以外はいらない
image.png
環境変数には今はやめておく。手動で一番下D:\Python39D:\Python39\Scriptsをあとで設定しておくといいだろう。(確かインストーラーに自動設定させると一番上になるので、後で何気なく「python」としたときにびっくりする可能性がある)
image.png

Python3xx/Scriptsにはパスを通しておく。コマンドラインからはpip3.xxでバージョンを分けて利用可能だ。
しかしpython.exeの名前を変えると動かなくなるのでpython.exeはバージョンごとに別の名前で呼ぶことができない。
そこでバッチファイルを作る。

python3.9.bat
%~dp0\python.exe %*

こんなのでいい。これにて、コマンドラインで
pip3.9と打てば3.9のpipが弄れるし、
python3.9と打てば3.9のpythonで実行できる。

普通にpythonと打てば(誤って今回の作業でパスの一番上に設定してなければ)今までデフォルトだったpythonバージョンが起動できる。敢えてpython3.xxとすることで任意のバージョンのpythonを起動できるというワケだ。

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?