0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

仮想環境内でのpythonのバージョン変更

Posted at

仮想環境でのバージョン変更

pythonのバージョン変更を行なった際に、仮想環境内でのみ、バージョン変更が反映されていないことに気が付いた。

調べてみると、やはり仮想環境でのバージョンは、仮想環境作成時のバージョンに固定されるらしく、仮想環境のクリアを行う必要があると判明した。

バージョン変更の手順

初めに、クリアを行うとpip installしていたものが全て削除されしまうので、それへの対応を行うため、以下のコマンドをターミナルで実行する。

ルートディレクトリにrequirements.txtを作成し,
$ touch requirements.txt

現在の環境でインストールしているパッケージとバージョンを書き込む。
$ pip freeze > requirements.txt

この作業を行うことで、バージョン変更後に、
pip install -r requirements.txt
を行うことで、インストールしていたパッケージとバージョンを一括でインストールできる。

以上の作業を行なった後に、
python -m venv [venvディレクトリ] --clear
を実行し、仮想環境のクリアを行う。

仮想環境に入り直し、バージョンを確認すると、変更されていると思う。

最後に

自分が仮想環境でのバージョン変更が反映されないことに悩んだので、誰かの助けになれば嬉しいです。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?