6

When is it necessary to specify modules to include? Doesn't py2exe search and include whatever is needed per: http://www.py2exe.org/index.cgi/FAQ?

And why does it include modules that are not being used, such as ["Tkconstants", "Tkinter", "tcl", "wx"] (I'm using Qt, but have wx installed on my PC) that then need to be excluded?

tosa
  • 411
  • 1
  • 3
  • 23

1 Answers1

7

py2exe tries to create a graph of all the dependencies, starting with your entry point script. It can't always get it 100% correct, which is why you are provided the includes and excludes options to fine tune the package.

Refer to options here: http://www.py2exe.org/index.cgi/ListOfOptions

Sometimes modules you didn't want will get included and if this happens just add them to the exclude. I suppose the answer to your question would be: manage the setup.py manually when the out-of-the box options don't package it exactly how you want.

The help files for py2exe actually include a bunch of tips and tricks... one specifically addressing your issue with Tk being included: http://www.py2exe.org/index.cgi/TkInter

The index of the tips and tricks is here: http://www.py2exe.org/index.cgi/Py2Exe

I've built a ton of apps using the very similar py2app for osx. Over the course of different versions, sometimes they change the way it discovers dependencies. It also uses various "recipes" for how to handle certain packages like Qt. A newer version of p2app suddenly started including all of the PyQt modules instead of just the two I used. So, I had to add them to my excludes.

jdi
  • 90,542
  • 19
  • 167
  • 203
  • But why does it handle popular packages like pandas? – user3841581 Jan 20 '18 at 13:15
  • @user3841581 are you asking why it doesn't handle pandas automatically? – jdi Jan 20 '18 at 18:32
  • 1
    Yes, Even when I include it in the includes of the setup.py file. When I try to make the executable file. It does make the file but when I run it disappear. When I put it on debug mode, I see that it disappear because. – user3841581 Jan 21 '18 at 00:36
  • @user3841581 sorry but your problem is not clear to me. You should probably post your own new question with an example of what you are trying and the result you are seeing. Like I said, some libraries use import tricks that make it hard for py2exe to detect. So you have to manually help it with your dependencies – jdi Jan 21 '18 at 01:04
  • I opened a new question. https://stackoverflow.com/questions/48423149/making-a-python-file-that-include-pandas-dataframe-using-py2exe – user3841581 Jan 24 '18 at 13:01