文書の表示以前のリビジョンバックリンク文書の先頭へ この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。 ====== VirtualEnv & VirtualEnvWrapper で作る Python 2.7 仮想環境 ====== 本家: [[https://virtualenv.pypa.io/|virtualenv]]\\ ソースコード: [[git>pypa/virtualenv|pypa/virtualenv: Virtual Python Environment builder]]\\ ===== Linux 編 ===== ==== virtualenv のインストール ==== <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>pip</b> install <b class=HIK>--user</b> virtualenv </pre></html></WRAP> <WRAP color_command><html><pre> </pre></html></WRAP> </WRAP> === 使い方 === <code> $ virtualenv -p /usr/bin/python2.7 py27dj110 $ source ./py27dj110/bin/activate (py27dj110) $ (py27dj110) $ deactivate $ </code> ==== virtualenvwrapper のインストール ==== パッケージをインストールする。 <code> $ sudo pip install virtualenvwrapper </code> インストール先パスを確認する。 <code> $ which virtualenvwrapper.sh /usr/bin/virtualenvwrapper.sh </code> ==== virtualenvwrapper の設定(ユーザー毎) ==== .bashrc に上記のパスを設定する。 <code> $ vi ~/.bashrc </code> Linux の設定例 <code> # User specific aliases and functions if [ -f /usr/bin/virtualenvwrapper.sh ]; then export WORKON_HOME=$HOME/.virtualenvs source /usr/bin/virtualenvwrapper.sh fi </code> .bashrc を実行して設定を有効化する。 <code> $ source ~/.bashrc </code> virtualenvwrapper の動作確認を行う。 <code> $ mkvirtualenv --help Usage: virtualenv [OPTIONS] DEST_DIR Options: --version show program's version number and exit -h, --help show this help message and exit -v, --verbose Increase verbosity 〜省略〜 </code> ===== Windows 編 ===== ==== MinGW Shell のインストール ==== - [[http://sourceforge.net/projects/mingw/|MinGW - Minimalist GNU for Windows]] より [[http://sourceforge.net/projects/mingw/files/latest/download|mingw-get-inst-20120426.exe]] をダウンロードする。 - mingw-get-inst-20120426.exe を実行して、MSYS Base System のチェックをオンにしてインストールする。 ==== MinGW Shell による環境構築 ==== - [スタート] - [すべてのプログラム] - [MinGW] より MinGW Shell を起動する。 - Vim をインストールする。<code> $ mingw-get install msys-vim </code> - Vim に日本語の設定を行う。(これをやらないと日本語キーボードの操作が上手く効かない)<code> $ vim .vimrc </code><code> set encoding=japan set fileencodings=sjis </code> ==== virtualenv のインストール ==== <code> $ pip install virtualenv </code> ==== virtualenvwrapper のインストール ==== パッケージをインストールする。 <code> $ pip install virtualenvwrapper </code> ==== virtualenvwrapper の設定(ユーザー毎) ==== .bashrc に alias やパスを設定する。 <code> $ vim .bashrc </code> ※以下は Python が C:\Python27 にインストールされている場合。 <code> alias l.='ls -d .* --color=tty' alias ll='ls -l --color=tty' alias ls='ls --color=tty' alias vi='vim' export WORKON_HOME=$HOME/.virtualenvs export MSYS_HOME=/c/MinGW/msys/1.0 source /c/Python27/Scripts/virtualenvwrapper.sh </code> .bashrc を実行して設定を有効化する。 <code> $ source ~/.bashrc </code> virtualenvwrapper の動作確認を行う。 <code> $ mkvirtualenv --help Usage: virtualenv [OPTIONS] DEST_DIR Options: --version show program's version number and exit -h, --help show this help message and exit -v, --verbose Increase verbosity 〜省略〜 </code> ===== 使い方 ===== ==== virtualenv で切替可能な環境の一覧を表示 ==== <code> $ workon </code> ==== 環境切替 ==== <code> $ workon py27dj14_webapp </code> ===== 参考文献 ===== [[http://blog.livedoor.jp/corbie/archives/3940485.html|corbieのブログ:MinGWインストールメモ]]\\ python/virtualenvwrapper.txt 最終更新: 2023/07/28 03:19by ともやん