using py2exe with wxPython and Matplotlib

前端 未结 4 754
你的背包
你的背包 2021-02-04 14:22

I\'m trying to generate an .exe file from a python script that uses wxPython and Matplotlib and it looks like to be impossible.

The imports I\'m doing (related with Matp

4条回答
  •  攒了一身酷
    2021-02-04 14:57

    There are a number of problems with matplotlib.get_py2exe_datafiles(), as convenient as it would be if it worked. It's also a good idea to specify which backend to use. Here's a working matplotlib import I recently used:

    from distutils.core import setup
    import py2exe
    from glob import glob
    
    import matplotlib       #Import then use get_py2exe_datafiles() to collect numpy datafiles.
    matplotlib.use('wxagg') #Specify matplotlib backend. tkagg must still be included else error is thrown.
    
    data_files = [
                ("Stuff", glob(r'C:\ProjectFolder\Stuff\*.*')) 
                ,("dlls", glob(r'C:\ProjectFolder\dlls\*.dll'))  
                ,("pyds", glob(r'C:\ProjectFolder\pyds\*.pyd')) # py2exe specified pyd's 
                ]
    # Extend the tuple list because matplotlib returns a tuple list.      
    data_files.extend(matplotlib.get_py2exe_datafiles())  #Matplotlib - pulls it's own files
    
    options =   {'py2exe':{#'bundle_files': 1,                                 # Bundle files to exe
                            'includes': ["matplotlib.backends.backend_tkagg"]  # Specifically include missing modules
                            ,'excludes': ['_gtkagg', 'tkagg']                  # Exclude dependencies. Reduce size.
                          }
                }   
    
    setup(
    name='ProjectName'
    ,options = options  
    ,data_files=data_files
    ,console=['projectname.py']
    )
    

提交回复
热议问题