37
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

Python複数version環境をPythonz, virtualenvで管理

バージョン管理をPythonz, 仮想環境をvirtualenvで構築

virtualenv, wrapper環境設定

install

$ sudo pip install virtualenv virtualenvwrapper

.zshrcにvirtualenv設定

virtualenv環境を ~/.virtualenvs とする場合

## virtualenv, virtualenvwrapper
which virtualenvwrapper.sh > /dev/null
if [ $? -eq 0 ]; then
    source `which virtualenvwrapper.sh`
    mkdir -p ~/.virtualenvs
    export WORKON_HOME=~/.virtualenvs
    export PIP_RESPECT_VIRTUALENV=true
fi

Pythonz環境設定

install

$ curl -kL https://raw.github.com/saghul/pythonz/master/pythonz-install | bash

.zshrcにPythonz設定

# Pythonz
if [ -s $HOME/.pythonz/etc/bashrc ]; then
    source $HOME/.pythonz/etc/bashrc
fi

複数Python version install

$ pythonz install 2.7.5
$ pythonz install 2.6.9
$ pythonz install 3.3.3

# 確認
$ pythonz list

==>
  CPython-2.6.9
  CPython-2.7.5
  CPython-3.3.3

Pythonz + virtualenv

仮想環境作成

$ mkvirtualenv -p ~/.pythonz/pythons/CPython-2.6.9/bin/python2.6 v2.6.9 && deactivate

$ mkvirtualenv -p ~/.pythonz/pythons/CPython-2.7.5/bin/python2.7 v2.7.5 && deactivate

$ mkvirtualenv -p ~/.pythonz/pythons/CPython-3.3.3/bin/python3.3 v3.3.3 && deactivate

環境切り替え & 削除

# activate
$ workon v2.7.5

# deactivate (to System)
$ deactivate

# remove
$ rmvirtualenv v2.6.9

[参考]
・virtualenvwrapper コマンドリファレンス
http://virtualenvwrapper-docs-ja.readthedocs.org/en/latest/command_ref.html

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
37
Help us understand the problem. What are the problem?