3

Dear python experts in the world wide web,

I really wish to get helped in this problem I have with pyinstaller.

I wish to convert a python script to an executable so that i can distribute to my friends and colleagues. Previously, I have converted the same python script to .exe file however I have accidentally deleted that file and I now have a new machine that I have installed python 3.7.8, pyinstaller version 3.6 and matplotlib version 3.2.2.

The .py file has tkinter library on it for a simple GUI and the rest is just data analytics that use numpy, pandas libraries and matplotlib fr data visualization. Additionally, there is a yfinance library to pull stock data from yahoo finance website. The output of this program is just a pdf file of the matplotlib plots of chosen stock indexes.

I can run this python code just fine in IDLE or jupyter notebook.

But as i convert it to the executable, the program does not load up and in console i have the following error message:

runtime error: could not find matplotlibrc file; your matplotlib install is broken

I have tried to re-install matplotlib package to different version such as 3.0, 3.1.3, etc. but then i ended up with the same runtime error message.

Could you please let me of what went wrong and how to overcome such problem?

Below is the pyinstaller code that i used to convert the python to .exe:

C:\Users\isamshahab\Desktop\Work Stuffs\CoC\Stock\StockIndexSummaryTool>pyinstaller--onefile YFScrapping.py
'pyinstaller--onefile' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\isamshahab\Desktop\Work Stuffs\CoC\Stock\StockIndexSummaryTool>pyinstaller --onefile YFScrapping.py
103 INFO: PyInstaller: 3.6
103 INFO: Python: 3.7.8
104 INFO: Platform: Windows-10-10.0.18362-SP0
106 INFO: wrote C:\Users\isamshahab\Desktop\Work Stuffs\CoC\Stock\StockIndexSummaryTool\YFScrapping.spec
110 INFO: UPX is not available.
113 INFO: Extending PYTHONPATH with paths
['C:\\Users\\isamshahab\\Desktop\\Work '
 'Stuffs\\CoC\\Stock\\StockIndexSummaryTool',
 'C:\\Users\\isamshahab\\Desktop\\Work '
 'Stuffs\\CoC\\Stock\\StockIndexSummaryTool']
114 INFO: checking Analysis
114 INFO: Building Analysis because Analysis-00.toc is non existent
114 INFO: Initializing module dependency graph...
120 INFO: Caching module graph hooks...
133 INFO: Analyzing base_library.zip ...
3509 INFO: Processing pre-find module path hook   distutils
3510 INFO: distutils: retargeting to non-venv dir 'c:\\users\\isamshahab\\appdata\\local\\programs\\python\\python37\\lib'
5744 INFO: Caching module dependency graph...
5905 INFO: running Analysis Analysis-00.toc
5908 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\users\isamshahab\appdata\local\programs\python\python37\python.exe
6047 INFO: Analyzing C:\Users\isamshahab\Desktop\Work Stuffs\CoC\Stock\StockIndexSummaryTool\YFScrapping.py
11245 INFO: Processing pre-find module path hook   site
11246 INFO: site: retargeting to fake-dir 'c:\\users\\isamshahab\\appdata\\local\\programs\\python\\python37\\lib\\site-packages\\PyInstaller\\fake-modules'
13580 INFO: Processing pre-safe import module hook   setuptools.extern.six.moves
31348 INFO: Processing pre-safe import module hook   six.moves
31905 INFO: Processing pre-safe import module hook   urllib3.packages.six.moves
64089 INFO: Processing module hooks...
64090 INFO: Loading module hook "hook-certifi.py"...
64092 INFO: Loading module hook "hook-distutils.py"...
64094 INFO: Loading module hook "hook-encodings.py"...
64226 INFO: Loading module hook "hook-importlib_metadata.py"...
64228 INFO: Loading module hook "hook-IPython.py"...
64830 INFO: Excluding import 'PyQt5'
64836 INFO:   Removing import of PyQt5 from module IPython.external.qt_loaders
64837 INFO: Excluding import 'PyQt4'
64844 INFO:   Removing import of PyQt4 from module IPython.external.qt_loaders
64845 INFO: Excluding import 'matplotlib'
64852 INFO:   Removing import of matplotlib from module IPython.core.pylabtools
64852 INFO:   Removing import of matplotlib.pyplot from module IPython.core.pylabtools
64853 INFO:   Removing import of matplotlib.backend_bases from module IPython.core.pylabtools
64853 INFO:   Removing import of matplotlib._pylab_helpers from module IPython.core.pylabtools
64853 INFO:   Removing import of matplotlib.figure from module IPython.core.pylabtools
64854 INFO: Excluding import 'gtk'
64866 INFO: Excluding import 'tkinter'
64874 INFO:   Removing import of tkinter from module IPython.lib.clipboard
64877 INFO: Excluding import 'PySide'
64885 INFO:   Removing import of PySide from module IPython.external.qt_loaders
64886 INFO: Loading module hook "hook-jedi.py"...
65251 INFO: Loading module hook "hook-jinja2.py"...
65282 INFO: Loading module hook "hook-jsonschema.py"...
65295 INFO: Loading module hook "hook-lib2to3.py"...
65302 INFO: Loading module hook "hook-lxml.etree.py"...
65308 INFO: Loading module hook "hook-matplotlib.backends.py"...
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 1015, in <module>
    rcParams = rc_params()
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 878, in rc_params
    return rc_params_from_file(matplotlib_fname(), fail_on_error)
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 731, in matplotlib_fname
    for fname in gen_candidates():
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 728, in gen_candidates
    yield os.path.join(get_configdir(), 'matplotlibrc')
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 276, in wrapper
    ret = func(**kwargs)
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 609, in get_configdir
    return _get_config_or_cache_dir(_get_xdg_config_dir())
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 562, in _get_xdg_config_dir
    return os.environ.get('XDG_CONFIG_HOME') or str(Path.home() / ".config")
AttributeError: type object 'Path' has no attribute 'home'
66344 INFO: Loading module hook "hook-matplotlib.py"...
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 1015, in <module>
    rcParams = rc_params()
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 878, in rc_params
    return rc_params_from_file(matplotlib_fname(), fail_on_error)
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 731, in matplotlib_fname
    for fname in gen_candidates():
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 728, in gen_candidates
    yield os.path.join(get_configdir(), 'matplotlibrc')
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 276, in wrapper
    ret = func(**kwargs)
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 609, in get_configdir
    return _get_config_or_cache_dir(_get_xdg_config_dir())
  File "c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\matplotlib\__init__.py", line 562, in _get_xdg_config_dir
    return os.environ.get('XDG_CONFIG_HOME') or str(Path.home() / ".config")
AttributeError: type object 'Path' has no attribute 'home'
67281 INFO: Loading module hook "hook-nbconvert.py"...
67303 INFO: Loading module hook "hook-nbformat.py"...
67321 INFO: Loading module hook "hook-notebook.py"...
69240 INFO: Loading module hook "hook-numpy.core.py"...
69470 INFO: Loading module hook "hook-numpy.py"...
69472 INFO: Loading module hook "hook-pandas.py"...
70787 INFO: Loading module hook "hook-PIL.Image.py"...
71389 INFO: Loading module hook "hook-PIL.py"...
71398 INFO: Excluding import 'PyQt5'
71425 INFO:   Removing import of PyQt5 from module PIL.ImageQt
71452 INFO: Excluding import 'PyQt4'
71491 INFO: Import to be excluded not found: 'FixTk'
71516 INFO: Excluding import 'tkinter'
71558 INFO:   Removing import of tkinter from module PIL.ImageTk
71583 INFO: Excluding import 'PySide'
71626 INFO: Loading module hook "hook-PIL.SpiderImagePlugin.py"...
71661 INFO: Excluding import 'tkinter'
71694 INFO: Import to be excluded not found: 'FixTk'
71719 INFO: Loading module hook "hook-pkg_resources.py"...
72388 INFO: Processing pre-safe import module hook   win32com
73076 INFO: Excluding import '__main__'
73082 INFO:   Removing import of __main__ from module pkg_resources
73109 INFO: Loading module hook "hook-pydoc.py"...
73135 INFO: Loading module hook "hook-pygments.py"...
76203 INFO: Loading module hook "hook-pythoncom.py"...
76821 INFO: Loading module hook "hook-pytz.py"...
76942 INFO: Loading module hook "hook-pywintypes.py"...
77544 INFO: Loading module hook "hook-scipy.linalg.py"...
77547 INFO: Loading module hook "hook-scipy.py"...
77588 INFO: Loading module hook "hook-scipy.sparse.csgraph.py"...
77621 INFO: Loading module hook "hook-scipy.special._ellip_harm_2.py"...
77652 INFO: Loading module hook "hook-scipy.special._ufuncs.py"...
77687 INFO: Loading module hook "hook-setuptools.py"...
78862 INFO: Loading module hook "hook-sqlite3.py"...
79012 INFO: Loading module hook "hook-sysconfig.py"...
79014 INFO: Loading module hook "hook-ttkthemes.py"...
79567 INFO: Loading module hook "hook-win32com.py"...
80368 INFO: Loading module hook "hook-xml.dom.domreg.py"...
80369 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
80401 INFO: Loading module hook "hook-xml.py"...
80435 INFO: Loading module hook "hook-zmq.py"...
80970 INFO: Loading module hook "hook-_tkinter.py"...
81232 INFO: checking Tree
81233 INFO: Building Tree because Tree-00.toc is non existent
81271 INFO: Building Tree Tree-00.toc
81416 INFO: checking Tree
81417 INFO: Building Tree because Tree-01.toc is non existent
81450 INFO: Building Tree Tree-01.toc
81872 INFO: Looking for ctypes DLLs
82072 INFO: Analyzing run-time hooks ...
82111 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
82116 INFO: Including run-time hook 'pyi_rth_pkgres.py'
82122 INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'
82153 INFO: Including run-time hook 'pyi_rth_traitlets.py'
82188 INFO: Including run-time hook 'pyi_rth_mplconfig.py'
82221 INFO: Including run-time hook 'pyi_rth_mpldata.py'
82254 INFO: Including run-time hook 'pyi_rth__tkinter.py'
82287 INFO: Including run-time hook 'pyi_rth_certifi.py'
82401 INFO: Looking for dynamic libraries
85446 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\zmq\backend\cython\error.cp37-win_amd64.pyd
85477 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\zmq\backend\cython\utils.cp37-win_amd64.pyd
85494 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\zmq\backend\cython\socket.cp37-win_amd64.pyd
85522 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\zmq\backend\cython\_poll.cp37-win_amd64.pyd
85553 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\zmq\backend\cython\message.cp37-win_amd64.pyd
85578 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\zmq\backend\cython\_proxy_steerable.cp37-win_amd64.pyd
85609 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\zmq\backend\cython\_device.cp37-win_amd64.pyd
85644 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\zmq\backend\cython\_version.cp37-win_amd64.pyd
85672 WARNING: lib not found: libzmq.cp37-win_amd64.pyd dependency of c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\zmq\backend\cython\context.cp37-win_amd64.pyd
87233 INFO: Looking for eggs
87233 INFO: Using Python library c:\users\isamshahab\appdata\local\programs\python\python37\python37.dll
87267 INFO: Found binding redirects:
[]
87356 INFO: Warnings written to C:\Users\isamshahab\Desktop\Work Stuffs\CoC\Stock\StockIndexSummaryTool\build\YFScrapping\warn-YFScrapping.txt
88104 INFO: Graph cross-reference written to C:\Users\isamshahab\Desktop\Work Stuffs\CoC\Stock\StockIndexSummaryTool\build\YFScrapping\xref-YFScrapping.html
88721 INFO: checking PYZ
88721 INFO: Building PYZ because PYZ-00.toc is non existent
88750 INFO: Building PYZ (ZlibArchive) C:\Users\isamshahab\Desktop\Work Stuffs\CoC\Stock\StockIndexSummaryTool\build\YFScrapping\PYZ-00.pyz
95698 INFO: Building PYZ (ZlibArchive) C:\Users\isamshahab\Desktop\Work Stuffs\CoC\Stock\StockIndexSummaryTool\build\YFScrapping\PYZ-00.pyz completed successfully.
95874 INFO: checking PKG
95875 INFO: Building PKG because PKG-00.toc is non existent
95913 INFO: Building PKG (CArchive) PKG-00.pkg
140236 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
140777 INFO: Bootloader c:\users\isamshahab\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
140777 INFO: checking EXE
140810 INFO: Building EXE because EXE-00.toc is non existent
140850 INFO: Building EXE from EXE-00.toc
140889 INFO: Appending archive to EXE C:\Users\isamshahab\Desktop\Work Stuffs\CoC\Stock\StockIndexSummaryTool\dist\YFScrapping.exe
141049 INFO: Building EXE from EXE-00.toc completed successfully.

Below is the screenshot of the error message from the console of the .exe file:

enter image description here

thank you up front for your time and help.

best regards, MH

5
  • Are you able to locate matplotlibrc on your machine ? Commented Jul 2, 2020 at 19:18
  • Hi Eric, I did find a few matplotlibrc file if i search that in my local directory. Do i have to declare this in pyinstaller? If yes, could you please tell me how? thank you Commented Jul 3, 2020 at 1:33
  • Try copy one in the same folder as the exe. If I understand correctly the documentation at matplotlib.org/tutorials/introductory/… this should help fixing your issue. Commented Jul 3, 2020 at 1:36
  • Hi thank you. This works, however i now have another error message: modulenotfounderror no module named 'matplotlib.backends.backend_tkagg' Commented Jul 3, 2020 at 2:19
  • Hi, I have somehow managed to fix the backend_tkagg issue by adding a script in my main .py file. Eric, is there anyway I can wrap this python script without have to copy the matplotlibrc file to the exe directory? thank you Commented Jul 3, 2020 at 2:38

2 Answers 2

5

To summarize: matplotlib requires a config file names matplotlibrc to be found in one of 4 specific locations, the first one being the courant directory (see https://matplotlib.org/tutorials/introductory/customizing.html#the-matplotlibrc-file) One this file prepared as per need it can be embeeded in the exe by adding --add-data=matplotlibrc;. to the build command (replace ; with : for non-Windows systems)

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

3 Comments

Another option is to simply copy the file to your python directory. This worked for me!
You are a savior...I spent around a day or so to narrow this down. I copied the file to local directory and built it. Worked like a charm..
It would be nice to have this a little bit more spelled out. Where should --add-data be added?
0

Ensure you have Visual C++ Redistributable Package (vc_redist.x64.exe) installed on the machine where you use pyinstaller before you build the executable. See Error after using PyInstaller for script with Matplotlib

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.