简体   繁体   English

Python:无法在Mac上导入机械化模块

[英]Python: Unable to import mechanize module on Mac

I have mechanize module installed using easy_install but when I tried to import I get the following error: 我使用easy_install安装了机械化模块但是当我尝试导入时出现以下错误:

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,它确认我有机械化:

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. 我意识到,不仅机械化我使用easy_install安装的大多数外部模块都无法导入。 Is it due to the fact that I have macports installed..? 是因为我安装了macports吗?

This is what I get from echo $PATH echo $PATH 这是我从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) 我做了哪个python,看起来像mac ports在opt目录下安装python ...(不太确定)

$which python
/opt/local/bin/python

Looks like you have installed mechanize to python 2.6 provided with Os X, but you are running python interpreter installed from macports. 看起来你已经安装了与Os X一起提供的python 2.6的机械,但你正在运行从macports安装的python解释器。

You can run easy_install for python from macports with (for python 2.7): 您可以使用(对于python 2.7)从macports运行easy_install for python:

/opt/local/bin/easy_install-2.7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM