编辑提示:在开始删除/修改安装之前,请浏览StvnW的回答/总结,以确保您正在应用适合您的解决方案。
我已经安装了Python 2.7.5和pip [编辑:Mac OSX Mountain Lion]。我在终端中运行了“pip install praw”。一切顺利。当我运行Python并运行“import praw”时,我会得到:
...$ python
Python 2.7.5 (v2.7.5:ab05e7dd2788, May 13 2013, 13:18:45)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import praw
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named praw
当我安装praw时,出现以下情况:
从脚本中导入相同的ImportError。
$ pip install praw
Downloading/unpacking praw
Downloading praw-2.1.10.tar.gz (83kB): 83kB downloaded
Running setup.py egg_info for package praw
Requirement already satisfied (use --upgrade to upgrade): requests>=1.2.0 in
/usr/local/lib/python2.7/site-packages (from praw)
Requirement already satisfied (use --upgrade to upgrade): six in
/usr/local/lib/python2.7/site-packages (from praw)
Requirement already satisfied (use --upgrade to upgrade): update-checker>=0.6 in
/usr/local/lib/python2.7/site-packages (from praw)
Requirement already satisfied (use --upgrade to upgrade): setuptools in
/usr/local/lib/python2.7/site-packages/setuptools-1.1.6-py2.7.egg (from update-
checker>=0.6->praw)
Installing collected packages: praw
Running setup.py install for praw
Installing praw-multiprocess script to /usr/local/bin
Successfully installed praw
Cleaning up...
在Python中,如果我运行help('modules'),它会找不到。作为一个相对新手的Python用户,我没有通过谷歌搜索解决这个问题。希望能够得到一些提示。更新:我已经卸载了2.7.2版本,卸载了praw,并卸载(homebrew)pip。我运行了Python 2.7.5,它找不到该模块(正如你所预料的那样)。然后我使用easy_install重新安装了pip,现在2.7.5可以找到praw,但是出现了这个错误:
$ python
Python 2.7.5 (v2.7.5:ab05e7dd2788, May 13 2013, 13:18:45)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import praw
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/praw/__init__.py", line 43, in <module>
from update_checker import update_check
File "/Library/Python/2.7/site-packages/update_checker.py", line 11, in <module>
from pkg_resources import parse_version as V
ImportError: No module named pkg_resources
>>>
感谢迄今为止的帮助,虚假安装是问题1的根源。
最终问题的解决方案可以在此处找到:
我希望有一种方法可以为未来的读者总结这个问题,但我已经尝试了很多东西,不再记得哪个解决了什么。我基本上卸载了所有(python 2.7.2、2.7.5、praw、pip),从http://python.org/download/重新安装了2.7.5,使用easy_install(和sudo命令)而不是homebrew重新安装了pip,使用sudo命令重新安装了praw,并按照上面链接中的说明解决了随后的模块错误。希望可以帮到您 :)
import sys; print sys.path
,是否包含了/usr/local/python2.7/site-packages/? - Wooble