gpt4 book ai didi

Python:无法在 Mac 上导入 Mechanize 模块

转载 作者:行者123 更新时间:2023-12-04 16:20:09 24 4
gpt4 key购买 nike

我使用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

我意识到不仅 Mechanize 我使用 easy_install 安装的大多数外部模块都无法导入。是不是因为我安装了macports..?

这是我从 echo $PATH 得到的
回声 $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

最佳答案

看起来您已经将 Mechanize 安装到随 Os X 提供的 python 2.6,但您正在运行从 macports 安装的 python 解释器。

您可以使用(对于python 2.7)从macports运行easy_install for python:

/opt/local/bin/easy_install-2.7

关于Python:无法在 Mac 上导入 Mechanize 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8378060/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com