我使用--no-site-packages選項創建了virtualenv環境。激活virtualenv後,我注意到在「python」提示符處導入psycopg2會導入已過時的系統庫,但是在「python2.6」提示符處導入它會將我安裝的庫的較新版本導入到virtualenv 。Virtualenv在不應該使用系統軟件包時
這是爲什麼?我如何才能在啓用virtualenv時使用virtualenv軟件包?
我在OS X上,如果它很重要。
編輯迴應下面傑夫的評論:
同時有「巨蟒」,在我的virtualenv/bin目錄「python2.6的」可執行文件。 「python2.6」是一個「python」的符號鏈接,「python」是一個二進制文件。
(ice_development)[[email protected]:~] $ ls -l Virtualenv/ice_development/bin/
total 264
-rw-r--r-- 1 jacob staff 2086 Sep 8 18:13 activate
.....
-rwxr-xr-x 1 jacob staff 50720 Sep 8 18:13 python
lrwxr-xr-x 1 jacob staff 6 Sep 8 18:13 python2.6 -> python
隨着ENV激活,「哪個python」和「哪個python2.6」都指向ENV目錄。
(ice_development)[[email protected]:~] $ which python
/Users/jacob/Virtualenv/ice_development/bin/python
(ice_development)[[email protected]:~] $ which python2.6
/Users/jacob/Virtualenv/ice_development/bin/python2.6
(ice_development)[[email protected]:~] $
此外,在命令行使用可執行文件後,提示符是相同的。
(ice_development)[[email protected]:~] $ python2.6
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>> psycopg2.__version__
'2.2.2 (dt dec ext pq3)'
>>> quit()
(ice_development)[[email protected]:~] $ python
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>> psycopg2.__version__
'2.0.13 (dt dec ext pq3)'
>>> quit()
的〜/ ENV/lib中/ python2.6的/ site-packages目錄包含psycopg2的新版本(2.2.2):
(ice_development)[[email protected]:~] $ ls Virtualenv/ice_development/lib/python2.6/site- packages/
Twisted-10.1.0-py2.6-macosx-10.6-universal.egg setuptools-0.6c11-py2.6.egg
easy-install.pth setuptools.pth
pip-0.7.2-py2.6.egg txpostgres-0.3.0-py2.6.egg
psycopg2 zope.interface-3.6.1-py2.6-macosx- 10.6-universal.egg
psycopg2-2.2.2-py2.6.egg-info
然而,在不同的提示進口進口psycopg2兩個不同的版本。
提示符是相同的,因爲它們都使用相同的版本。我的2.6 virtualenv和non-virtual共享相同的時間戳。 – xnine 2010-09-10 00:11:21