Python: Unable to import mechanize module on Mac
Question: 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
    


Answer: 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):

    
    
    /opt/local/bin/easy_install-2.7
    

