本文介绍了无法从 site-packages 目录加载通过 pip 安装的 Python 模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试安装和使用印象笔记模块 (https://github.com/evernote/evernote-sdk-蟒蛇).我运行了 pip install evernote,它说安装成功了.

I am trying to install and use the Evernote module (https://github.com/evernote/evernote-sdk-python) . I ran pip install evernote and it says that the installation worked.

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

I can confirm that the evernote module exists in /usr/local/lib/python2.7/site-packages. However, when I try to run python -c "import evernote" I get the following error:

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 安装的其他模块时遇到了同样的问题.有帮助吗?

I am having this same problem with other modules installed with pip. Help?

我是一个超级新手,还没有编辑过那个 .bash-profile 文件.

I am a super newbie and have not edited that .bash-profile file.

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

python -c 'import sys; print "".join(sys.path)' Outputs the following:

/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 模块存在于模块目录中.

I seemed to have made progress towards a solution by adding export PYTHONPATH="/usr/local/lib/python2.7/site-packages" to my .bash_profile file. However, now when I run python -c 'from evernote.api.client import EvernoteClient' it tries to import oauth2, which fails with the same error. The ouath2 module is present in the module directory.

推荐答案

/usr/bin/python 是 OS X 自带的 python 的可执行文件./usr/local/lib 是仅用于用户安装的程序的位置,可能来自 Python.org 或 Homebrew.因此,您混合了不同的 Python 安装,而更改 Python 路径只是针对为不同安装安装的不同软件包的部分解决方法.

/usr/bin/python is the executable for the python that comes with OS X. /usr/local/lib is a location for user-installed programs only, possibly from Python.org or Homebrew. So you're mixing different Python installs, and changing the python path is only a partial workaround for different packages being installed for different installations.

为了确保你使用与特定python相关的pip,你可以运行python -m pip install ,或者去看看什么路径上的 pip 是或符号链接到.

In order to make sure you use the pip associated with a particular python, you can run python -m pip install <pkg>, or go look at what the pip on your path is, or is symlinked to.

这篇关于无法从 site-packages 目录加载通过 pip 安装的 Python 模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 04:36
查看更多