gpt4 book ai didi

python - pip 安装的包不在 sys.path 中

转载 作者:太空狗 更新时间:2023-10-30 01:38:42 27 4
gpt4 key购买 nike

我是一个 python 菜鸟。已经安装了 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

最佳答案

请注意,根据设计和要求,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

或者你可以只获取 freeze 的输出,然后在 virtualenv 中执行 pip install -r requirements.txt

关于python - pip 安装的包不在 sys.path 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11141191/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com