Search code examples
pythonpython-2.7anacondapy2execontinuum

Include all my python libraries to the exe generated by py2exe


I want to include all python libraries and dependencies that my python.exe uses to compile and run my programm on my computer, into the exe Generated by py2exe, I want that because py2exe **.exe* generated is still returning errors and aborts,

Thank you

Here libraries that I used in my programm:

from Tkinter import *  # POUR L'interface graphique
import tkFileDialog  # POUR l'ouverture d'
import csv
import ttk
import Tix as tix
import re  # regular exprun fichier
import tkMessageBox  # POUR un messageboxe pour quitter le programme
import py2exe, sys, os
import numpy as np
from threading import Thread
import datetime as dt
import pygal
from bokeh.plotting import figure, output_file, show
from datetime import datetime as time
import matplotlib.pyplot as plt
from PyQt4 import QtGui
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
from matplotlib import cm
from matplotlib.dates import date2num
from matplotlib.gridspec import GridSpec
import matplotlib.dates as mdates

And here my setup.exe script:

import sys
import os
import glob
import os.path

from distutils.core import setup
import py2exe
sys.setrecursionlimit(5000)

sys.argv.append('py2exe')
"""
setup(
    options = {'py2exe': { 'compressed': True}},
    windows = [{'script': "D:\Users\u156726\PycharmProjects\SFR_APP\SFR_APP_BIG_DATA.py"}],
    zipfile = None,
)
"""
import matplotlib
import glob

setup(console=['D:\Users\u156726\PycharmProjects\SFR_APP\SFR_APP.py'],options={
               'py2exe': {
                          'packages' :  ['matplotlib', 'pytz'],

                          }
                },

Solution

  • py2exe offers 'options' parameter to define a list of packages to include or exclude. When there are packages missing you can force py2exe to bundle those packages into the exe.

    Review to docs for more informations about all the options.

    includes = ['matplotlib', 'numpy', 'Tkinter', 'tcl', 'Tkconstants', ... ]
    excludes = ['_gtkagg', '_tkagg', 'curses', 'pywin.debugger', 'pywin.debugger.dbgcon', 'pywin.dialogs' ]
    packages = []
    dll_excludes = []
    
    setup(
        options = {"py2exe": {"compressed": 0,
                              "optimize": 0,
                              "includes": includes,
                              "excludes": excludes,
                              "packages": packages,
                              "dll_excludes": dll_excludes,
                              "bundle_files": 1,
                              "dist_dir": ".",
                              "xref": False,
                              "skip_archive": False,
                              "ascii": False,
                              "custom_boot_script": '',
                             }
                  },
        console=...,
    )