安装了Mechanize,但Python无法找到模块

时间:2013-06-08 20:46:21

标签: python mechanize

我使用以下方法将mechanize安装到目录中:

sudo easy_install --always-unzip mechanize
Searching for mechanize
Best match: mechanize 0.2.5
Processing mechanize-0.2.5-py2.7.egg
mechanize 0.2.5 is already the active version in easy-install.pth, 

但是当我调用脚本scrape.py时,我收到了这个错误:

Traceback (most recent call last):
File "scrape.py", line 6, in <module>
from mechanize import Browser
ImportError: No module named mechanize

我在升级到Mac OSX 10.8(从10.6开始)之前使用过这个脚本并且乱用Java Ant,如果这有帮助的话。这是我的路径:

echo $PATH
    /opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/Current/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/local/ant/bin 

你能告诉我如何解决这个问题吗?

编辑:我解决了这个问题。在家中将.bash_profile的第一行设置为

# Setting PATH for MacPorts Python
# The orginal version is saved in .bash_profile.pysave
PATH="/opt/local/bin/python2.7:${PATH}"
export PATH

并在主目录中的.bash_profile中删除了其他版本的Python。

1 个答案:

答案 0 :(得分:0)

我修好了。在家中将.bash_profile的第一行设置为

# Setting PATH for MacPorts Python
# The orginal version is saved in .bash_profile.pysave
PATH="/opt/local/bin/python2.7:${PATH}"
export PATH

并在主目录中的.bash_profile中删除了其他版本的Python。

相关问题