1,105,534 Community Members

Mechanize not recognized by py2exe

Member Avatar
OrcaSoul
Newbie Poster
9 posts since May 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I have a Python script getData.py that uses Mechanize, and runs fine under the interpreter. It was installed using easy_install - and the install seemed to indicate it was completed.

The problem is, when I try to compile it using py2exe while in the folder of the script, and using the run line command:

python getData.py py2exe

I get the warning: "Import error: No Module named mechanize"...

I checked the environmental path and find the following:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files (x86)\Python;C:\Python25\Lib\site-packages;C:\Program Files (x86)\Common Files\Adobe\AGL

I did a search for mechanize and find an egg file in C:\Python25\Lib\site-packages named mechanize-0.1.7b-py2.5.

Not really understanding the "egg" thing, what do I have here that needs to be done?

Stephen

Member Avatar
shadwickman
Posting Pro in Training
495 posts since Jul 2007
Reputation Points: 159 [?]
Q&As Helped to Solve: 80 [?]
Skill Endorsements: 0 [?]
 
0
 

Is there a file in the C:\Python25\Lib\site-packages folder named mechanize.pth or a folder named mechanize in that directory? There should be, and the data in mechanize.pth should simply say "mechanize" (without the quotes).

Member Avatar
OrcaSoul
Newbie Poster
9 posts since May 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Is there a file in the C:\Python25\Lib\site-packages folder named mechanize.pth or a folder named mechanize in that directory? There should be, and the data in mechanize.pth should simply say "mechanize" (without the quotes).

No, neither one. The only Mechanized file is the .egg...in fact, a search of of the Python folder finds only that file. And a search of the entire drive didn't show it either.

Member Avatar
shadwickman
Posting Pro in Training
495 posts since Jul 2007
Reputation Points: 159 [?]
Q&As Helped to Solve: 80 [?]
Skill Endorsements: 0 [?]
 
0
 

Open the .egg in Notepad and see what sort of data in contains... I've personally never used mechanize, but then again I've never encountered a module that ran with only an egg file. It could be a common thing that I just have had no experience with though :P

Member Avatar
OrcaSoul
Newbie Poster
9 posts since May 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

It seems to have a lot of gibberish, with readable text scattered around. A little more readable in Wordpad, but still not a lot of useful info...I'm wondering if I need to execute the egg somehow?

Member Avatar
shadwickman
Posting Pro in Training
495 posts since Jul 2007
Reputation Points: 159 [?]
Q&As Helped to Solve: 80 [?]
Skill Endorsements: 0 [?]
 
0
 

From the py2exe site:
"py2exe does not currently (as of 0.6.5) work out of the box if some of your program's dependencies are in .egg form. "

So, here's some py2exe documentation about including .egg files in the .exe. I hope this will help you out :)

Member Avatar
OrcaSoul
Newbie Poster
9 posts since May 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks - it did help push me in what I think is the right direction...

First, I realized that I needed to extract the egg extracted from the first easy_install...

Did all that, no change...So I uninstalled everything - from Python to py2exe - and reinstalled, being very careful to follow the directions on the web pages. Everything looked OK, I wrote a small test script and it ran under the interpreter...ran py2exe to compile, and the script would not run...

I rechecked the site-packages folder - and mechanize was still a .egg...so something didn't work properly.

I then copied the .egg file to another folder, ran easy_install - which looked like it ran...When I checked it had created a dist folder, I found the test exe app - and it ran!

So, the lesson has been, always read the instruction one more time(!), and move the first egg out of the site-packages before you run them...

Now to see if this works for the full script...

Thanks for the help - I just needed that nudge in the right direction in order to see the obvious! :D

Question Answered as of 4 Years Ago by shadwickman
Member Avatar
pncampbell
Newbie Poster
1 post since Jul 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

The lazy mans version is ... delete the egg files and then reinstall mechanize (and and any other add-on libraries py2exe cant find) with

easy_install --always-unzip <library_name>

Job done

Oh and as a bonus, eclipse is also much happier with unpacked eggs

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article