2015年9月10日 星期四

[RR Python] 建立獨立開發環境 virtualenv virtualenvwrapper

python的威力是有許多已經被開發的模組可以使用
讓程式設計者能專注在程式功能與邏輯上

然而寫python程式最怕的就是使用不同的版本的模組,甚至是不同版本的python
virtualenv的介紹有提到:
"
The basic problem being addressed is one of dependencies and versions, and indirectly permissions. Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python2.7/site-packages (or whatever your platform’s standard location is), it’s easy to end up in a situation where you unintentionally upgrade an application that shouldn’t be upgraded.
 "

virtualenv / virtualenvwrapper (大致上)解決了這個問題

建立環境
mkvirtualenv test1

mkvirtualenv test1 -p /usr/bin/python3.3 

離開環境
deactivate
使用先前建立的環境
workon test1
刪除先前建立的環境
rmvirtualenv test1

 
 
 
 
Szymon Lipiński 有相當簡潔的安裝與使用範例

Virtualenv Tutorial Part 2

sudo pip install virtualenvwrapper

mkdir ~/.virtualenvs


A Primer on virtualenv 也提供了使用virtualenv的建議

 

沒有留言:

張貼留言