我安裝了Canopy和Anaconda。我的默認是Canopy,但是當我啓動screen
時,我得到了Anaconda。這在大部分時間對我很有用,但是這次我需要在screen
中使用Canopy。Python虛擬環境找不到python模塊
我認爲解決方案是創建一個虛擬的環境,我這樣做是這樣的:
cd /path/to/project
virtualenv my_project
問題:virtualenv中不能看到我安裝的Python模塊,如numpy的。
這裏是我的過程的其餘部分:
[email protected]:~/path/to/my_project$ screen
[email protected]:~/path/to/my_project$ source activate lstm_project
(lstm_project) [email protected]:~/path/to/my_project$ python
Enthought Canopy Python 2.7.6 | 64-bit | (default, Sep 15 2014, 17:36:10)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named numpy
下面是sys.path中的輸出:
>>> print sys.path
['', '/user/path/to/my_project',
'/opt/enthought/canopy-1.5.1/appdata/canopy-1.5.1.2730.rh5-x86_64/lib/python27.zip',
'/opt/enthought/canopy-1.5.1/appdata/canopy-1.5.1.2730.rh5-x86_64/lib/python2.7',
'/opt/enthought/canopy-1.5.1/appdata/canopy-1.5.1.2730.rh5-x86_64/lib/python2.7/plat-linux2',
'/opt/enthought/canopy-1.5.1/appdata/canopy-1.5.1.2730.rh5-x86_64/lib/python2.7/lib-tk',
'/opt/enthought/canopy-1.5.1/appdata/canopy-1.5.1.2730.rh5-x86_64/lib/python2.7/lib-old',
'/opt/enthought/canopy-1.5.1/appdata/canopy-1.5.1.2730.rh5-x86_64/lib/python2.7/lib-dynload',
'/user/path/to/my_project/lib/python2.7/site-packages']
我怎樣才能讓我的virtualenv承認我已經在全球安裝的軟件包?
可能是一個愚蠢的問題,但你確實在*激活virutalenv後安裝模塊* – errata