【问题标题】:Python: Unable to import mechanize module on MacPython:无法在 Mac 上导入机械化模块
【发布时间】:2011-12-04 19:42:10
【问题描述】:

我使用 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 得到的 回声 $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 将 python 安装在 opt 目录下...(不太确定)

$which python
/opt/local/bin/python

【问题讨论】:

  • 为什么这是负面标记..?
  • 我也在想同样的事情。
  • 也许它将模块安装在与 Python 预期不同的目录中?我不熟悉它对模块过程的解析。

标签: python mechanize macports easy-install


【解决方案1】:

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

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

/opt/local/bin/easy_install-2.7

【讨论】:

  • 非常感谢 mac 端口命令将默认 python 版本设置为 2.7 我在 2.6 上
  • IIRC 它是“sudo port select python python27”
猜你喜欢
  • 2010-09-21
  • 2018-04-17
  • 1970-01-01
  • 2019-08-23
  • 2010-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多