Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CX_FREEEZE, INNO : could not find the matplotlib data files

I made an executable file from python scripts and cx_freeze. The freezing looks ok. But I have problmes when I use INNO to create a setup file. I can create the setup and successfully deploy the application. But while I launch it from "Program Files (x86)" directory I have a runtime error : Could not find the matplotlib data files

C:\Program Files (x86)\GLADDataExtraction>main
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
    exec(code, m.__dict__)
  File "main.py", line 8, in <module>
  File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 947, in <module>
    rcParams = rc_params()
  File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 865, in rc_params
    return rc_params_from_file(fname, fail_on_error)
  File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 930, in rc_params_from_file
    ret['datapath'] = get_data_path()
  File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 312, in wrapper
    ret = func(*args, **kwargs)
  File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 655, in _get_data_path_cached
    defaultParams['datapath'][0] = _get_data_path()
  File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 651, in _get_data_path
    raise RuntimeError('Could not find the matplotlib data files')
RuntimeError: Could not find the matplotlib data files

I looked for explanations on internet quite extensively without success. There are many topics linked to py2exe but none for cx_freeze. I investigated my cx_freeze setup.py file, displayed below :

#!/usr/bin/python
# -*- coding: utf-8 -*-
# Python 2.7
# 02/2011

import sys, os
from cx_Freeze import setup, Executable
import matplotlib

#############################################################################
# préparation des options

# chemins de recherche des modules

path='D:\\IceSat\\tests\\test_executable\\test_GLASDataExtraction'

if os.path.exists(path):
    print "exist"

if path in sys.path:
    print "OK"
else:
    print "insert"
    sys.path.append(path)


path = sys.path + ["package_interface", "package_traitement"]

##build_exe_options = { 'packages': ['scipy'],
##                     "include_files": [('C:\\Python27\\Lib\\site-packages\\scipy\\special\\_ufuncs.pyd','_ufuncs.pyd')]}




# options d'inclusion/exclusion des modules
##includes = ["sip", "matplotlib"]
includes = ["sip"]
##excludes = ["tk","tcl"]
excludes = []
##packages = ["scipy", "scipy.signal", "scipy.special", "matplotlib", "matplotlib.mpl-data"]
##packages = ["scipy", "scipy.signal", "scipy.special", "matplotlib",  "matplotlib.backends"]
##packages = ["scipy", "scipy.signal", "scipy.special", "matplotlib"]
packages = ["scipy", "scipy.signal", "scipy.special"]
##packages = ["scipy", "scipy.signal", "scipy.special", "matplotlib", "matplotlib.backends", "matplotlib.mpl-data"]



### construction du dictionnaire des options
options = {"path": path,
           "includes": includes,
           "excludes": excludes,
           "packages": packages,
##           "include_files": includefiles,
           "include_files":[(matplotlib.get_data_path(),"mpl-data")]
##           "include_files":[(matplotlib.get_data_path(),"HDE")]
####           "include_files":[matplotlib.get_data_path(),"C:\\Python27\\Lib\site-packages\\matplotlib\\mpl-data"]
##           "bin_path_includes": binpathincludes
           }


# création du setup
setup(
    name = "GLASDataExtraction",
    version = "1",
    description = "Extraction et analyse de data GLAS",
    author = "Henri",
    options = {"build_exe": options},
##    executables = [cible_1]
    executables=[Executable("main.py")]
    )

There are many comments because I tried to simplify as possible the setup.py file without impact in build directory. After launching

python setup.py build

in DOS window, directory 'build/exe... ' are created. Inside there are :

  • library.zip file with many packages (matplotlib is inside but without mpl-data which doesn't looks like a package as there is no init.py file).
  • many .pyd files
  • 4 directory : imageformats, mpl-data, tcl, tk. mpl-data is there with its content.

Then, my setup file is created with INNO application in "Program Files (x86)" directory. I launch the installation with this setup file. It looks ok. My program directory is created with few directories and files. Files from "C:\Python27\Lib\site-packages\matplotlib\mpl-data" are among those files. But when I launch the .exe file, I have the error "RuntimeError: Could not find the matplotlib data files".

My configuration is :

  • WINDOWS 7 64 bits
  • python 2.7 64 bits
  • cx_freeze 4.3.3
  • inno 5.5.5
  • pyqt4
like image 686
henri d Avatar asked Nov 01 '22 18:11

henri d


1 Answers

Thank you Thomas, yes I first run the frozen exe before make the installer. it was OK. I found a solution: while importing directory, inno copies all the files in the same directory as the exe file (Program Files (x86) directory). But if I define the same directory as frozen exe, I have to add mpl-data in the path Dest dir. in iss INNO script:
the line in the script is :

\build\exe.win-amd64-2.7\mpl-data\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs

I add mpl-data directory in the path in iss file, in order to have the same relative path from the exe to mpl-data file in the install directory and in frozen directory :

\build\exe.win-amd64-2.7\mpl-data\*"; DestDir: "{app}\mpl-data\"; Flags: ignoreversion recursesubdirs createallsubdirs

I compile, install... it works

like image 192
henri d Avatar answered Nov 16 '22 08:11

henri d