我是一个蟒蛇菜鸟。已经安装了virtualenv和pip,一切看起来都不错,但是当尝试导入通过pip安装的软件包时,python找不到它们。我在OS X上并在/usr/bin
中拥有系统python 2.6,因此通过软件包安装程序将2.7安装到/usr/local/bin
。在安装pip和virtualenv时,我确保通过将PATH设置为/usr/local/bin
来使用2.7 python。
(pysite)sbeam@pris ~/Sites]$ pip freeze
Django==1.4
Markdown==2.1.1
psycopg2==2.4.5
wsgiref==0.1.2
(pysite)sbeam@pris ~/Sites]$ echo $PYTHONPATH
(pysite)sbeam@pris ~/Sites]$ which python
/Users/sbeam/.virtualenvs/pysite/bin/python
(pysite)sbeam@pris ~/Sites]$ env | grep VIRTUAL
VIRTUALENVWRAPPER_PROJECT_FILENAME=.project
VIRTUAL_ENV=/Users/sbeam/.virtualenvs/pysite
VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
VIRTUALENVWRAPPER_HOOK_DIR=/Users/sbeam/.virtualenvs
VIRTUALENVWRAPPER_LOG_DIR=/Users/sbeam/.virtualenvs
(pysite)sbeam@pris ~/Sites]$ python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> from pprint import pprint as pp
>>> pp(sys.path)
['',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/distribute-0.6.27-py2.7.egg',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-0.7.2-py2.7.egg',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages']
>>> import markdown
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named markdown
答案 0 :(得分:0)
请注意,默认情况下,根据设计和要求virtualenv
的新版本(1.7+)不包含site-packages
。
http://www.virtualenv.org/en/latest/news.html
您可以在virtualenv创建中明确使用--system-site-packages
,请参阅:
http://www.virtualenv.org/en/latest/index.html#the-system-site-packages-option
或者您可以直接获取冻结的输出,并在virtualenv中执行pip install -r requirements.txt