Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pyinstaller: building a python exe using matplotlib

I have been trying to replicate the example of this post, to generate an executable with pyinstaller but with no success. I am on a linux OS.

the exe I try to build is based on this code (test.py afterwards)

from pylab import *
from matplotlib import pyplot as plt

figure(1, figsize=(6,6))
ax = axes([0.1, 0.1, 0.8, 0.8])

labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
fracs = [15, 30, 45, 10]
explode=(0, 0.05, 0, 0)

pie(fracs, explode=explode, labels=labels,
                autopct='%1.1f%%', startangle=90)

title('Pie Chart Example', bbox={'facecolor':'0.8', 'pad':5})

show()

To create the executable I run

pyinstaller --onefile test.py

I tried with version 3.0 (official version in the pip install) and version 3.1.dev of pyinstaller. Both compile but when I run the executable I got

./test 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 363, in load_module
    exec(bytecode, module.__dict__)
  File "/usr/share/pyshared/pylab.py", line 1, in <module>
    from matplotlib.pylab import *
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 363, in load_module
    exec(bytecode, module.__dict__)
  File "/usr/share/pyshared/matplotlib/__init__.py", line 157, in <module>
    from matplotlib.compat import subprocess
ImportError: No module named compat
test returned -1

I read that a possible error could be linked to my $PYTHONPATH (see this post) but even with a clean $PYTHONPATH environement, I have the same error.

Also I do not understand why the executable is looking for a file in the /usr/ directory when it should be standalone.

Any advices would be welcome. Thanks.

PS: This is the output of the compilation with pyinstaller v3.0. Note that to make it working I had to comment 'PyQt4' and 'PyQt5' in the file /usr/local/lib/python2.7/dist-packages/PyInstaller/hooks/hook-PIL.py as suggested in this post.

pyinstaller --onefile test.py 
22 INFO: PyInstaller: 3.0
22 INFO: Python: 2.7.6
22 INFO: Platform: Linux-3.16.0-30-generic-x86_64-with-Ubuntu-14.04-trusty
40 INFO: wrote /home/paugam/Src/stackimage/test.spec
44 INFO: UPX is not available.
45 INFO: Extending PYTHONPATH with /home/paugam/Src/stackimage
45 INFO: checking Analysis
45 INFO: Building Analysis because out00-Analysis.toc is non existent
45 INFO: Initializing module dependency graph...
46 INFO: Initializing module graph hooks...
85 INFO: running Analysis out00-Analysis.toc
102 INFO: Analyzing /home/paugam/Src/stackimage/test.py
135 INFO: Processing pre-find module path hook   distutils
6044 INFO: Processing pre-find module path hook   site
6044 INFO: site: retargeting to fake-dir '/usr/local/lib/python2.7/dist-packages/PyInstaller/fake-modules'
11904 INFO: Looking for import hooks ...
11906 INFO: Processing hook   hook-distutils.py
11906 INFO: Processing hook   hook-sysconfig.py
11906 INFO: Processing hook   hook-xml.py
11907 INFO: Processing hook   hook-PIL.py
11907 INFO: Excluding import 'FixTk'
11910 WARNING:   Removing import 'FixTk'
11910 INFO: Excluding import 'Tkinter'
11910 INFO: Excluded import 'PySide' not found
11910 INFO: Processing hook   hook-httplib.py
11911 INFO: Processing hook   hook-pydoc.py
11911 INFO: Excluding import 'Tkinter'
11911 INFO: Processing hook   hook-PyQt4.py
11912 WARNING: Hidden import 'PyQt4._qt' not found (probably old hook)
11912 INFO: Processing hook   hook-encodings.py
12264 INFO: Processing hook   hook-_tkinter.py
12327 INFO: checking Tree
12327 INFO: Building Tree because out00-Tree.toc is non existent
12327 INFO: Building Tree out00-Tree.toc
12365 INFO: checking Tree
12366 INFO: Building Tree because out01-Tree.toc is non existent
12366 INFO: Building Tree out01-Tree.toc
12380 INFO: Processing hook   hook-matplotlib.backends.py
12798 INFO:   Matplotlib backend "GTK": added
13108 INFO:   Matplotlib backend "GTKAgg": added
13420 INFO:   Matplotlib backend "GTKCairo": added
13631 INFO:   Matplotlib backend "MacOSX": ignored
    cannot import name _macosx
13893 INFO:   Matplotlib backend "Qt4Agg": added
14120 INFO:   Matplotlib backend "TkAgg": added
14246 INFO:   Matplotlib backend "WX": ignored
    No module named wx
14464 INFO:   Matplotlib backend "WXAgg": ignored
    No module named wx

** (-c:4422): WARNING **: Couldn't connect to accessibility bus: Failed to connect to socket /tmp/dbus-psXhVLD3F9: Connection refused
14809 INFO:   Matplotlib backend "GTK3Cairo": added

** (-c:4423): WARNING **: Couldn't connect to accessibility bus: Failed to connect to socket /tmp/dbus-psXhVLD3F9: Connection refused
15146 INFO:   Matplotlib backend "GTK3Agg": added
15394 INFO:   Matplotlib backend "WebAgg": added
15605 INFO:   Matplotlib backend "agg": added
15819 INFO:   Matplotlib backend "cairo": added
15942 INFO:   Matplotlib backend "emf": ignored
    No module named backend_emf
16253 INFO:   Matplotlib backend "gdk": added
16467 INFO:   Matplotlib backend "pdf": added
16754 INFO:   Matplotlib backend "pgf": added
16966 INFO:   Matplotlib backend "ps": added
17181 INFO:   Matplotlib backend "svg": added
17403 INFO:   Matplotlib backend "template": added
17844 INFO: Processing pre-safe import module hook   gi.repository.GObject
18382 INFO: Processing hook   hook-PIL.Image.py
18632 INFO: Processing hook   hook-matplotlib.py
18745 INFO: Processing hook   hook-xml.dom.domreg.py
18746 INFO: Processing hook   hook-PyQt4.QtGui.py
18904 WARNING: Hidden import 'PyQt4._qt' not found (probably old hook)
18905 INFO: Processing hook   hook-pytz.py
18905 INFO: Processing hook   hook-setuptools.py
18906 INFO: Processing hook   hook-xml.sax.py
18906 INFO: Processing hook   hook-PIL.SpiderImagePlugin.py
18906 INFO: Excluded import 'FixTk' not found
18906 INFO: Excluding import 'Tkinter'
18907 INFO: Processing hook   hook-PyQt4.QtCore.py
18939 WARNING: Hidden import 'PyQT4._qt' not found (probably old hook)
18940 INFO: Processing hook   hook-xml.dom.py
18940 INFO: Processing hook   hook-gtk.py
18941 WARNING: Hidden import 'gtkglext' not found (probably old hook)
18942 WARNING: Hidden import 'gdkgl' not found (probably old hook)
18943 WARNING: Hidden import 'gdkglext' not found (probably old hook)
18943 WARNING: Hidden import 'gtk.gdk' not found (probably old hook)
18944 WARNING: Hidden import 'gtk.gtkgl' not found (probably old hook)
18944 WARNING: Hidden import 'gtk.gtkgl._gtkgl' not found (probably old hook)
18945 WARNING: Hidden import 'gtkgl' not found (probably old hook)
19008 INFO: Processing hook   hook-gi.repository.GObject.py
19076 INFO: Processing pre-safe import module hook   gi.repository.GLib
19101 WARNING: Hidden import 'gi._gobject.option' not found (probably old hook)
19101 INFO: Processing hook   hook-gi.py
19102 WARNING: Hidden import 'gi._error' not found (probably old hook)
19102 INFO: Processing hook   hook-gi.repository.GLib.py
19216 INFO: Looking for ctypes DLLs
19261 WARNING: library rpcrt4.dll required via ctypes not found
19303 INFO: Analyzing run-time hooks ...
19318 INFO: Including run-time hook 'pyi_rth_pkgres.py'
19320 INFO: Including run-time hook 'pyi_rth__tkinter.py'
19321 INFO: Including run-time hook 'pyi_rth_gi.py'
19321 INFO: Including run-time hook 'pyi_rth_qt4plugins.py'
19323 INFO: Including run-time hook 'pyi_rth_mplconfig.py'
19324 INFO: Including run-time hook 'pyi_rth_mpldata.py'
19345 INFO: Looking for dynamic libraries
21278 INFO: Looking for eggs
21278 INFO: Python library not in binary depedencies. Doing additional searching...
21314 INFO: Using Python library /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
21347 INFO: Warnings written to /home/paugam/Src/stackimage/build/test/warntest.txt
21354 INFO: checking PYZ
21354 INFO: Building PYZ because out00-PYZ.toc is non existent
21355 INFO: Building PYZ (ZlibArchive) /home/paugam/Src/stackimage/build/test/out00-PYZ.pyz
22059 INFO: checking PKG
22059 INFO: Building PKG because out00-PKG.toc is non existent
22059 INFO: Building PKG (CArchive) out00-PKG.pkg
40123 INFO: Bootloader /usr/local/lib/python2.7/dist-packages/PyInstaller/bootloader/Linux-64bit/run
40123 INFO: checking EXE
40123 INFO: Building EXE because out00-EXE.toc is non existent
40123 INFO: Building EXE from out00-EXE.toc
40123 INFO: Appending archive to EXE /home/paugam/Src/stackimage/dist/test
like image 339
paugam Avatar asked Nov 09 '22 01:11

paugam


1 Answers

I uninstalled matplotlib and reinstalled it to version 1.5.1 and it worked. It seems to be a bug back in 1.4.1- versions. Refer here.

like image 179
MeadowMuffins Avatar answered Nov 14 '22 21:11

MeadowMuffins