3

I have racked my brain on getting Mechanize to install without an egg in Win7. I have tried the easy_install --allways-unzip method. The easy_install -Z method. Added .pth file in the site-packages directory. Added combinations of the above.

Py2exe doesn't play nice with egg files. If you have got this working, please reply.

Thanks - Brad


Some of the links I followed are:

Mechanize not being installed by easy_install?

How to install mechanize for Python 2.7?

http://www.daniweb.com/software-development/python/threads/204941

http://www.velocityreviews.com/forums/t691937-re-mechanize-not-recognized-by-py2exe.html

Community
  • 1
  • 1
Verohomie
  • 123
  • 1
  • 8

2 Answers2

4

If you haven't already read it there is a section on py2exe website about dealing with eggs. I don't know how effective it is (I never install eggs), and py2exe can be tricky enough without dealing with an egg installed packages. I would do the one of the following:

  1. Download the mechanize source package, unzip it and edit its setup.py to change the zip_safe option to False. Then install mechanize from the command line:

    python setup.py install
    
  2. use pip to do the install:

    pip install mechanize
    

    Of course you'd have to install pip first (easy_install pip). pip installs packages flat by default. (fyi - if you end up using pip on Windows you need to beware that it can't handle python packages that require compiling. Mechanize won't be a problem, but if it's something you start using with any regularity...)

Other than the egg issue there is nothing that I can see in mechanize's package structure that would indicate that py2exe would have any problems picking it up once it has been installed flat.

Mark Gemmill
  • 5,889
  • 2
  • 27
  • 22
  • Both methods to install mechanize worked. Py2exe builds without exceptions. When I run the executable a log file is generated with the following ImportError: No Module Name Inspect. When I run the program from the source I get no errors and it runs OK. Any ideas, thanks for the post - Brad. – Verohomie Sep 21 '11 at 16:51
0

The last install of mechanize used method 1 from @markgemmill as posted above.

I kept getting a log error: ImportError: No module named inspect when running my executable.

After adding inspect, calendar, etc... to the includes[] in py2exe setup.py, I realized that I should maybe I should change my code from:

    import mechanize
        to
    from mechanize import *

This worked. The executable generated from py2exe runs!

A noob mistake. Always learning... Brad

Verohomie
  • 123
  • 1
  • 8