LoginSignup
2
2

More than 5 years have passed since last update.

pyvenvで別のバージョンのPythonを指定したい

Posted at

/* とりあえずUbuntu14.04では確認しました。 */

やりたいこと

すでにenv2_7というディレクトリをpyvenvで作ったと仮定して。

$ source env2_7/bin/activate
$ python -V
Python 2.7.6

ということをやりたかったのです。

結論

作った仮想環境ディレクトリのbinの下のpythonのシンボリックリンクを変えてやる。

余談

生成された仮想環境のbin以下に、各Pythonへのシンボリックリンクが張られているらしく、
そのうちのpythonのシンボリックリンクを変えてactivateしたら、実際うまく行った。

コマンドと見てみる

こうなっているのを、

$ tree env2_7
env2_7
├── bin
│   ├── activate
│   ├── activate.csh
│   ├── activate.fish
│   ├── python -> python3.4
│   ├── python3 -> python3.4
│   └── python3.4 -> /usr/bin/python3.4
...

シンボリックリンクを張り直して、

$ ln /usr/bin/python2.7 env2_7/bin/python --symbolic

こうした。


$ tree env2_7
env2_7
├── bin
│   ├── activate
│   ├── activate.csh
│   ├── activate.fish
│   ├── python -> /usr/bin/python2.7
│   ├── python3 -> python3.4
│   └── python3.4 -> /usr/bin/python3.4
...

最初のpyvenvコマンドでできる方法をご存じの方がいらっしゃいましたら、ぜひコメント欄にてツッコミしてください。

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