Rabarberski
Rabarberski

Reputation: 24922

py2exe: why are some standard modules NOT included?

My python program uses plugins (python files) which I import dynamically using __import__. I bundle my python program into a Windows exe using py2exe.

I've just spend searching 2 hours why my plugin python file couldn't be loaded properly from the .exe version. I got an ImportError: "no module named urllib2" It appeared my plugin was using urllib2 (through an import urllib2 statement), and that standard library module was apparently not bundled into the exe. Other modules used in the plugin (re, urllib, ...) gave no problem, but perhaps they were already references in python files I statically include in my program.

How can I know which standard Python library modules py2exe bundles by default in the exe? (so I know whether I or somebody else can use them in a plugins). The py2exe documentation doesn't give an hints, except for saying that it includes a lot of modules from the standard library.

Upvotes: 3

Views: 1045

Answers (1)

markm
markm

Reputation: 906

To see which modules are included look inside the library.zip (if there is no library.zip file - then try opening the EXE in any ZIP application - or rename it to .ZIP and try and open it).

You will be able to see a list of *.pyc. You can look at the list of files and directories to get an impression of which modules are included or not.

If you require a specific package to be added - add it to the 'packages' list.

As to why it doesn't include everything or how it chooses to include some and not others? My understanding is that py2exe looks in your code to figure out what you are using and includes those (and some that it probably needs itself) but maybe it also has some heuristics to add other modules too (I haven't checked :)

Upvotes: 4

Related Questions