2

I finished my first complete python program and am trying to create an exe. I did successfully build the exe, but it runs and does nothing. I'm guessing it didn't include all the packages. I can specify these with the build_exe_options in cx_Freeze, but I don't know the difference between packages and excludes.

These are all the imports I use in my program

import os
import smtplib
from datetime import datetime, timedelta
from ftplib import FTP_TLS
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

Below is my current setup file

from cx_Freeze import setup, Executable

setup(
    name = "FTPConnect",
    version = "1.0",
    description = "Connects to FTP to download docs",
    executables = [Executable("main.py")]
)

I'm guessing I can do something like this, correct?

from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os", "smtplib", "datetime", "ftplib", "email.mime.text", "email.mime.multipart" ], "excludes": []}

setup(
      name = "FTPConnect",
      version = "1.0",
      description = "Connects to FTP to download docs",
      options = {"build_exe": build_exe_options},
      executables = [Executable("main.py")]
)
Stephen Day
  • 63
  • 2
  • 8
  • I just experienced a difficulty that look similar (https://stackoverflow.com/questions/45734926/build-a-exe-for-windows-from-a-python-3-script-importing-pyqtgraph-and-opening). Did you eventually get some improvements ? – Stéphane Aug 24 '17 at 08:48

1 Answers1

4

Well, 'packages' will include a package with all its submodules, while 'exclude' will exclude the modules listed.

Read more about all possible values here: http://cx-freeze.readthedocs.io/en/latest/distutils.html#build-exe. It's a list of command line options, but the will work in your script too.

There are a lot of other options allowing to include and exclude zipped modules, DLLs binaries and so on.

Hope this helps!

linusg
  • 6,289
  • 4
  • 28
  • 78
  • 1
    So if I were to use 'includes' instead of packages, I could just import only specific parts of a package then? And if I wanted the whole package, I would just use packages? Why would I ever want to exclude a module, it should be excluded if I didn't include it, right? – Stephen Day Mar 16 '17 at 20:09
  • Sometimes 3th-party modules import a lot of crap you don't need, these will just blow up your exe. By excluding them, they'll be ... excluded from your exe :) – linusg Mar 16 '17 at 20:11
  • Makes sense. Thanks! – Stephen Day Mar 16 '17 at 20:22