2016年11月7日 星期一

Using Python with Virtualenv


很多時候會面臨到不同開發專案會使用不同的開發環境(Python)與套件
除此之外, 還可能會使用不同的套件, 更可能會面臨到相同套件不同版本的問題
使用Virtualenv可以解決困擾
In many situations, you have to develop your projects in various environments to meet each needs.
However install all the needed model package and python version will make your box very dirty.
Virtualenv can solve this kinds of problem.

1. Create an virtual environment in a directory
$ cd proj_directory
$ virtualenv -p /usr/local/bin/python3.5 virtualenv_name

2. Start virtual env
$ source virtualenv_name/bin/activate

除此之外, 此時亦可以透過pipe安裝套件到virtual environment, 與世隔絕
Besides, you can install other python module package in virtual environment by using pipe command, to ensure the developing environment isolate.

3. 結束目前virtual environment
3. End current virtual environment
$ deactivate

刪除virtual environment
If you want to get ride of the virtual environment, using the following command.
$ cd proj_directory
$ rmvirtualenv virtualenv_name

Reference:

Virtual Environments

沒有留言: