我使用以下命令将 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
你能告诉我如何解决这个问题吗?
编辑:我解决了这个问题。将 home 中 .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。