无法从site-packages目录加载通过pip安装的Python模块

时间:2014-08-13 00:36:55

标签: python macos bash module evernote

我正在尝试安装和使用Evernote模块(https://github.com/evernote/evernote-sdk-python)。我跑了pip install evernote,它说安装工作正常。

我可以确认evernote模块存在于/usr/local/lib/python2.7/site-packages中。但是,当我尝试运行python -c "import evernote"时,我收到以下错误:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named evernote

这是我的.bash-profile

的内容
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

# Setting PATH for Python 3.3
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.3/bin:${PATH}"
export PATH
export PATH=$PATH:/usr/local/bin/

我在使用pip安装的其他模块时遇到同样的问题。帮助

编辑:我是一个超级新手,并没有编辑.bash-profile文件。

编辑:python -c 'import sys; print "\n".join(sys.path)'输出以下内容:

/Library/Python/2.7/site-packages/setuptools-1.3.2-py2.7.egg
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC
/Library/Python/2.7/site-packages

编辑:我似乎已经通过在export PYTHONPATH=“/usr/local/lib/python2.7/site-packages”文件中添加.bash_profile来取得进展。但是,现在当我运行python -c 'from evernote.api.client import EvernoteClient'时,它会尝试导入oauth2,它会因同样的错误而失败。 ouath2模块存在于模块目录中。

5 个答案:

答案 0 :(得分:77)

/usr/bin/python是OS X附带的python的可执行文件。/usr/local/lib仅适用于用户安装的程序,可能来自Python.org或Homebrew。所以你要混合不同的Python安装,而改变python路径只是针对不同安装安装的不同软件包的部分解决方法。

为了确保使用与特定python相关联的pip,您可以运行python -m pip install <pkg>,或者查看路径上的pip是什么,或者是符号链接的到。

答案 1 :(得分:56)

我明白了!我添加了这一行:

export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages

到我的.bash_profile,现在我可以导入存储在该目录中的模块。感谢所有回答的人。

答案 2 :(得分:5)

我遇到了类似的问题,它与/usr/local/lib/python2.7/site-packages相关,对组和其他组件没有读写权限,而且它们归root所有。这意味着只有root用户才能访问它们。

试试这个:

$ sudo chmod -R go+rX /usr/local/lib/python2.7/site-packages

答案 3 :(得分:4)

这对我的类似问题没有任何帮助。相反,我必须修复新安装的文件权限才能导入。这通常是一个显而易见的事情,但在安装模块/软件包时使用sudo并不是那么多。

答案 4 :(得分:-3)

只需输入终端:

sudo pip install pillow

并输入import(无论您喜欢什么)或输入from(无论您喜欢什么)import(无论您喜欢什么)。