2

I have a problem when trying to make an executable with a Python application.

For doing this, I'm using Py2exe with the 2.7 version of Python.

My application have 3 python scripts -> IHM_monotone_flux_GTC.py which is the one who launch a graphical interface

and then 2 others scripts: -> lectureDonnees.py -> main.py

In order to create an executable I made a setup.py file which is surely incomplete:

from distutils.core import setup import py2exe

setup(windows=['IHM_monotone_flux_gtc.py'])

Unfortunetaly, it doesn't work and I got this error message:

Traceback (most recent call last):
     File "IHM_monotone_flux_gtc.py", line 16, in <module>
     File "main.pyc", line 22, in <module>
     File "matplotlib\__init__.pyc", line 838, in <module>
     File "matplotlib\__init__.pyc", line 749, in rc_params
     File "matplotlib\__init__.pyc", line 664, in matplotlib_fname
     File "matplotlib\__init__.pyc", line 292, in wrapper
     File "matplotlib\__init__.pyc", line 585, in _get_data_path_cached
     File "matplotlib\__init__.pyc", line 581, in _get_data_path
   RuntimeError: Could not find the matplotlib data files

Thanks for any help. (I'm working with Windows XP)

Cédric.

2 Answers 2

4

You will need to copy the mpl-data folder too. Check this official wiki site http://www.py2exe.org/index.cgi/MatPlotLib

import matplotlib
...
setup(
    ...
    data_files=matplotlib.get_py2exe_datafiles(),
)

You will need something like this in your setup.py for py2exe. hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

0

It looks like from Matplotlib 3.3.0 the function get_py2exe_datafiles() doesn't exist anymore: https://matplotlib.org/stable/api/prev_api_changes/api_changes_3.3.0.html

To know what to do, please look at: https://github.com/py2exe/py2exe/issues/71 and https://github.com/py2exe/py2exe/issues/169

SUMMARY:

I currently have matplotlib 3.6.0, wxpython 4.2.0, py2exe 0.13.0.0:

2 cases:

A - test.py with matplotlib only:

setup.py:

from distutils.core import setup
import py2exe

setup(
    windows = ["test.py"]
)

should work

B - test.py with matplotlib and wxpython:

setup.py:

from distutils.core import setup
import py2exe

setup(
    windows = ["test.py"]
)

should work BUT the need is ALSO to check stuff in py2exe/hooks.py as described in https://github.com/py2exe/py2exe/issues/169

def hook_matplotlib(finder, module):
    """matplotlib requires data files in a 'mpl-data' subdirectory in
    the same directory as the executable.
    """
    import ast
    from pkg_resources._vendor.packaging import version as pkgversion

    import matplotlib

    mpl_data_path = matplotlib.get_data_path()
    finder.add_datadirectory("mpl-data", mpl_data_path, recursive=True)

    # --- COMMENT BELOW LINE NOT TO EXCLUDE WXPYTHON ---------------------
    ##finder.excludes.append("wx")
    ## XXX matplotlib requires tkinter which modulefinder does not
    ## detect because of the six bug.
    # ------------------------------------------------------------------

    ...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.