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 开发者_C百科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
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:
Download the
mechanize
source package, unzip it and edit itssetup.py
to change thezip_safe
option toFalse
. Then install mechanize from the command line:python setup.py install
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 usingpip
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.
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
精彩评论