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

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).

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.

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

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?

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

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

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

how to find directory of python in linux ?????? i have some problem becouse i'm new here in kali linux during installation fb.py erorr accured no module named mechanize please freinds help meeeeeeeee ?

@Mhmmd In a terminal, paste this

python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"

and hit enter. It will print the path to the python library.

Also in the forum please start new threads with the 'python' tag instead of reviving old threads.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.