我通过下载 tar.gz 包并执行 python setup.py install 安装了 oauth2。但是我收到了这个错误
bash-3.2$ python
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import oauth2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named oauth2
>>>
oauth2 的路径在 PYTHONPATH 中(所以这不应该是问题所在)因为我将此行添加到 ~/.bashrc:
PYTHOHPATH=$PYTHONPATH:/Users/me/Downloads/oauth2-1.5.211/
但是,当我这样做时:
bash-3.2$ cd /System/Library/Frameworks/Python.framework/Versions/2.7/
bash-3.2$ ls
Extras Headers Mac Python Resources _CodeSignature bin include lib
bash-3.2$ Python
Python 2.7.1 (r271:86882M, Nov 30 2010, 09:39:13)
[GCC 4.0.1 (Apple Inc. build 5494)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import oauth2
>>>
它工作得很好。知道我应该如何安装 oauth2 以避免 python 的 ImportError 吗?
P/S: 这是 python 命令的 simlink
python -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
请您参考如下方法:
我没有答案,但我有一些一般性的建议:
运行 python setup.py install 使用您打算从中使用它的相同 python(在您的情况下,一个是大写的,另一个不是)。
我总是export 我的 bashrc 变量以确保它们是全局的,但我不确定这是你的问题。
在 pwd 中运行脚本时,始终使用 ./ 运行它们。在您的情况下,将 python 作为 ./Python 运行,以确信您正在运行您认为正在运行的可执行文件。
检查 PYTHONPATH 的拼写。如果您认为自己做对了,请执行 import sys; print('\n'.join(sys.path)) 从你的 python session 中并确保适当的目录在那里
