全てのコマンドは次のようにターミナル上で使用されます。
WORKON_HOME に新たな仮想環境を作成します。
構文:
mkvirtualenv [options] ENVNAME
全てのコマンドラインオプションは virtualenv へ直接渡されます。新しい仮想環境は初期化された後に自動的にアクティブ化されます。
$ workon
$ mkvirtualenv mynewenv
New python executable in mynewenv/bin/python
Installing distribute.............................................
..................................................................
..................................................................
done.
(mynewenv)$ workon
mynewenv
(mynewenv)$
See also
全ての仮想環境を表示します。
構文:
lsvirtualenv [-b] [-l] [-h]
-b | ブリーフモード、冗長な出力を無効にする |
-l | ロングモード、冗長な出力を有効にする(デフォルト) |
-h | lsvirtualenv のヘルプを表示する |
See also
WORKON_HOME の仮想環境を削除します。
構文:
rmvirtualenv ENVNAME
カレントの仮想環境を削除する前に deactivate を実行しなければなりません。
(mynewenv)$ deactivate
$ rmvirtualenv mynewenv
$ workon
$
See also
WORKON_HOME の仮想環境を複製します。
構文:
cpvirtualenv ENVNAME TARGETENVNAME
Note
コピー操作で作成された仮想環境は 再配置可能 です。
$ workon
$ mkvirtualenv source
New python executable in source/bin/python
Installing distribute.............................................
..................................................................
..................................................................
done.
(source)$ cpvirtualenv source dest
Making script /Users/dhellmann/Devel/virtualenvwrapper/tmp/dest/bin/easy_install relative
Making script /Users/dhellmann/Devel/virtualenvwrapper/tmp/dest/bin/easy_install-2.6 relative
Making script /Users/dhellmann/Devel/virtualenvwrapper/tmp/dest/bin/pip relative
Script /Users/dhellmann/Devel/virtualenvwrapper/tmp/dest/bin/postactivate cannot be made relative (it's not a normal script that starts with #!/Users/dhellmann/Devel/virtualenvwrapper/tmp/dest/bin/python)
Script /Users/dhellmann/Devel/virtualenvwrapper/tmp/dest/bin/postdeactivate cannot be made relative (it's not a normal script that starts with #!/Users/dhellmann/Devel/virtualenvwrapper/tmp/dest/bin/python)
Script /Users/dhellmann/Devel/virtualenvwrapper/tmp/dest/bin/preactivate cannot be made relative (it's not a normal script that starts with #!/Users/dhellmann/Devel/virtualenvwrapper/tmp/dest/bin/python)
Script /Users/dhellmann/Devel/virtualenvwrapper/tmp/dest/bin/predeactivate cannot be made relative (it's not a normal script that starts with #!/Users/dhellmann/Devel/virtualenvwrapper/tmp/dest/bin/python)
(dest)$ workon
dest
source
(dest)$
作業する仮想環境を変更、または表示します。
構文:
workon [environment_name]
environment_name が与えられない場合は標準出力に利用可能な仮想環境を表示します。
$ workon
$ mkvirtualenv env1
New python executable in env1/bin/python
Installing distribute.............................................
..................................................................
..................................................................
done.
(env1)$ mkvirtualenv env2
New python executable in env2/bin/python
Installing distribute.............................................
..................................................................
..................................................................
done.
(env2)$ workon
env1
env2
(env2)$ workon env1
(env1)$ echo $VIRTUAL_ENV
/Users/dhellmann/Devel/virtualenvwrapper/tmp/env1
(env1)$ workon env2
(env2)$ echo $VIRTUAL_ENV
/Users/dhellmann/Devel/virtualenvwrapper/tmp/env2
(env2)$
仮想環境からシステムにインストールされた Python のバージョンに切り替えます。
構文:
deactivate
Note
このコマンドは、実際は virtualenv の一部ですが、まさに workon が行うようにアクティブ化のために、処理の前後にフック機能を提供するためにラップされます。
$ workon
$ echo $VIRTUAL_ENV
$ mkvirtualenv env1
New python executable in env1/bin/python
Installing distribute.............................................
..................................................................
..................................................................
done.
(env1)$ echo $VIRTUAL_ENV
/Users/dhellmann/Devel/virtualenvwrapper/tmp/env1
(env1)$ deactivate
$ echo $VIRTUAL_ENV
$
See also
カレントのアクティブ化された仮想環境内へ移動するためのショートカットを提供する2つの機能があります。
$VIRTUAL_ENV へカレントワークディレクトリを移動します。
構文:
cdvirtualenv [subdir]
cdvirtualenv を呼び出すと、カレントワークディレクトリを仮想環境($VIRTUAL_ENV)のトップへ移動します。オプションの引数はそのパスに追加されて、サブディレクトリへ直接的に移動することもできます。
$ mkvirtualenv env1
New python executable in env1/bin/python
Installing distribute.............................................
..................................................................
..................................................................
done.
(env1)$ echo $VIRTUAL_ENV
/Users/dhellmann/Devel/virtualenvwrapper/tmp/env1
(env1)$ cdvirtualenv
(env1)$ pwd
/Users/dhellmann/Devel/virtualenvwrapper/tmp/env1
(env1)$ cdvirtualenv bin
(env1)$ pwd
/Users/dhellmann/Devel/virtualenvwrapper/tmp/env1/bin
$VIRTUAL_ENV の site-packages へカレントワークディレクトリを移動します。
構文:
cdsitepackages [subdir]
仮想環境の site-packages ディレクトリへの正確なパスは Python のバージョンに依存するので、 cdsitepackages は cdvirtualenv lib/python${pyvers}/site-packages のショートカットです。さらにオプションの引数は直接移動する site-packages 内の階層構造のディレクトリを指定することもできます。
$ mkvirtualenv env1
New python executable in env1/bin/python
Installing distribute.............................................
..................................................................
..................................................................
done.
(env1)$ echo $VIRTUAL_ENV
/Users/dhellmann/Devel/virtualenvwrapper/tmp/env1
(env1)$ cdsitepackages PyMOTW/bisect/
(env1)$ pwd
/Users/dhellmann/Devel/virtualenvwrapper/tmp/env1/lib/python2.6/site-packages/PyMOTW/bisect
lssitepackages を呼び出すと、カレントのアクティブ化された仮想環境の site-packages ディレクトリのコンテンツを表示します。
構文:
lssitepackages
$ mkvirtualenv env1
New python executable in env1/bin/python
Installing distribute.............................................
..................................................................
..................................................................
done.
(env1)$ $ workon env1
(env1)$ lssitepackages
distribute-0.6.10-py2.6.egg pip-0.6.3-py2.6.egg
easy-install.pth setuptools.pth
カレントのアクティブ化された仮想環境の Python パスへ指定したディレクトリを追加します。
構文:
add2virtualenv directory1 directory2 ...
システムの site-pacakges ディレクトリに存在しないインストール済みのパッケージやそれぞれの仮想環境にインストールしたくないパッケージを共有したいときがあります。1つの解決方法はその仮想環境の site-packages ディレクトリへシンボリックリンクを張ることです。しかし、 add2virtualenv を使用して site-packages 内の .pth ファイルへそういったパッケージを含めることで、PYTHONPATH へ拡張ディレクトリを追加することも簡単です。
site-packages ディレクトリ内の virtualenv_path_extensions.pth と名付けられたパスファイルへそのディレクトリ名が追加されます。
James Bennett と Jannis Leidel から提供されたものに基づいています。