Python:无法在 Mac 上导入 mechanize 模块
我使用 easy_install 安装了 mechanize 模块,但是当我尝试导入时,出现以下错误:
Python 2.6.7 (r267:88850, Nov 21 2011, 14:59:21)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import mechanize
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named mechanize
只是为了确认我已经安装了 mechanize,我再次执行了 easy_install 并确认我已经安装了 mechanize:
easy_install mechanize
Searching for mechanize
Best match: mechanize 0.2.5
Processing mechanize-0.2.5-py2.6.egg
mechanize 0.2.5 is already the active version in easy-install.pth
Using /Library/Python/2.6/site-packages/mechanize-0.2.5-py2.6.egg
Processing dependencies for mechanize
Finished processing dependencies for mechanize
我意识到不仅机械化了大多数外部模块我使用 easy_install 安装的文件无法导入。是不是因为我安装了macports..?
这是我从 echo $PATH
得到的 echo $PATH
/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/Users/N-H/DevApps/android-sdk-mac_x86/platform-tools:/Users/N-H/DevApps/android-sdk-mac_x86/tools:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/opt/subversion/bin/:/opt/subversion/bin:/usr/bin/java:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/N-H/DevApps/android-sdk-mac_86/tools:/Library/grails-1.3.6/bin:/opt/subversion/bin:/usr/bin/java:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/N-H/DevApps/android-sdk-mac_86/tools:/usr/bin/gcc-4.2
我做了 which python 并且看起来像 mac ports 在 opt 目录下安装了 python...(不太确定)
$which python
/opt/local/bin/python
I have mechanize module installed using easy_install but when I tried to import I get the following error:
Python 2.6.7 (r267:88850, Nov 21 2011, 14:59:21)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import mechanize
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named mechanize
Just to confirm that I have installed mechanize I did easy_install again and it confirm that I have mechanize:
easy_install mechanize
Searching for mechanize
Best match: mechanize 0.2.5
Processing mechanize-0.2.5-py2.6.egg
mechanize 0.2.5 is already the active version in easy-install.pth
Using /Library/Python/2.6/site-packages/mechanize-0.2.5-py2.6.egg
Processing dependencies for mechanize
Finished processing dependencies for mechanize
I realize that not only mechanize most of the external modules that I install using easy_install don't get available for import. Is it due to the fact that I have macports installed..?
This is what I get from echo $PATH
echo $PATH
/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/Users/N-H/DevApps/android-sdk-mac_x86/platform-tools:/Users/N-H/DevApps/android-sdk-mac_x86/tools:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/opt/subversion/bin/:/opt/subversion/bin:/usr/bin/java:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/N-H/DevApps/android-sdk-mac_86/tools:/Library/grails-1.3.6/bin:/opt/subversion/bin:/usr/bin/java:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/N-H/DevApps/android-sdk-mac_86/tools:/usr/bin/gcc-4.2
I did which python and looks like mac ports installs python under opt directory... (not really sure)
$which python
/opt/local/bin/python
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您已经将 mechanize 安装到了 Os X 提供的 python 2.6,但您正在运行从 macports 安装的 python 解释器。
您可以从 macports 运行适用于 python 的 easy_install(对于 python 2.7):
Looks like you have installed mechanize to python 2.6 provided with Os X, but you are running python interpreter installed from macports.
You can run easy_install for python from macports with (for python 2.7):