1

For anyone who can help... My issue is this: I have created a Python application that I wish to turn into a cross platform executable one file. However, though pyinstaller is executed without a problem, the executable is not working. Specifically it says "Failed to execute the script". I have tried with both onefile and onedir options. My Python application's imports are these (yes, they are a lot but necessary):

import os
import sqlite3
import sys
import easygui
sys.path.append("/usr/bin/qgis")
sys.path.append("~\.qgis2\python\plugins")
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from geopy.exc import GeocoderServiceError
from geopy.geocoders import Nominatim
from sklearn.decomposition import *
from sklearn.metrics import homogeneity_score, adjusted_rand_score
#from PyQt4.QtCore import Qt, QFileInfo, QSize
from PyQt4.QtNetwork import *
from PyQt4.Qsci import *
from qgis.core import *
from qgis.gui import *
from qgis.utils import *
from PyQt4.QtXml import QDomDocument
from itertools import product
# Creating reports
from reportlab.lib import colors
from reportlab.lib.enums import TA_CENTER
from reportlab.lib.pagesizes import portrait, A4
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.platypus import SimpleDocTemplate, Paragraph, Table, TableStyle, PageBreak, Spacer, Image
# Using separate python scripts
from cluster_gui import Ui_Cluster_Analysis
from clustering_algorithms import *
from clustering_metrics import *

My application is written in Python 2.7 and the pyinstaller version is 3.2. Browsing the forums, I read that there is a known issue with PyQt libraries and pyinstaller but, whatever the suggestions are, I haven't been able to solve the problem. Another suggestion was to write:

from PyQt4 import QtCore, QtGui

instead of

from PyQt4.QtCore import *
from PyQt4.QtGui import *

I don't know whether it is a PyQt issue or something else. Please any suggestion how to solve this or any remark about some of the libraries not compatible with pyinstaller or any guess how to analyze the issue.

Thank you all in advance.

EDIT: This is the result when I execute pyinstaller

pyinstaller --onefile --path=/usr/bin/qgis:~\.qgis2\python\plugins:/usr/lib/x86_64-linux-gnu --noupx --icon=clusterpoints.svg mycluster.py
16 INFO: PyInstaller: 3.2
16 INFO: Python: 2.7.12
16 INFO: Platform: Linux-4.4.0-38-generic-x86_64-with-Ubuntu-16.04-xenial
16 INFO: wrote /home/*****/Dropbox/mypythonfiles/mycluster.spec
23 INFO: UPX is not available.
26 INFO: Extending PYTHONPATH with paths
['/home/*****/Dropbox/mypythonfiles',
 '/usr/bin/qgis',
 '/home/*****/Dropbox/mypythonfiles/~.qgis2pythonplugins',
 '/usr/lib/x86_64-linux-gnu',
 '/home/*****/Dropbox/mypythonfiles']
28 INFO: checking Analysis
28 INFO: Building Analysis because out00-Analysis.toc is non existent
28 INFO: Initializing module dependency graph...
30 INFO: Initializing module graph hooks...
71 INFO: running Analysis out00-Analysis.toc
104 INFO: Caching module hooks...
105 INFO: Analyzing /home/*****/Dropbox/mypythonfiles/mycluster.py
2066 INFO: Processing pre-safe import module hook   _xmlplus
2528 INFO: Processing pre-find module path hook   distutils
4022 INFO: Processing pre-find module path hook   site
4022 INFO: site: retargeting to fake-dir '/usr/local/lib/python2.7/dist-packages/PyInstaller/fake-modules'
4040 INFO: Processing pre-safe import module hook   win32com
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ImportError: No module named win32com
4057 INFO: Processing pre-safe import module hook   win32com
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ImportError: No module named win32com
7136 INFO: Processing pre-safe import module hook   six.moves
17109 INFO: Loading module hooks...
17109 INFO: Loading module hook "hook-distutils.py"...
17110 INFO: Loading module hook "hook-sysconfig.py"...
17110 INFO: Loading module hook "hook-xml.py"...
17110 INFO: Loading module hook "hook-PIL.py"...
17114 INFO: Excluding import 'FixTk'
17119 INFO: Excluding import 'Tkinter'
17123 INFO: Excluding import 'PyQt5'
17127 WARNING:   Removing import PIL.ImageQt from module PyQt5
17128 WARNING:   Removing import PIL.ImageQt from module PyQt5.qRgba
17128 WARNING:   Removing import PIL.ImageQt from module PyQt5.QPixmap
17128 WARNING:   Removing import PIL.ImageQt from module PyQt5.QImage
17128 INFO: Excluding import 'PySide'
17132 WARNING:   Removing import PIL.ImageQt from module PySide.QPixmap
17132 WARNING:   Removing import PIL.ImageQt from module PySide.qRgba
17132 WARNING:   Removing import PIL.ImageQt from module PySide
17132 WARNING:   Removing import PIL.ImageQt from module PySide.QImage
17132 INFO: Excluding import 'PyQt4'
17138 WARNING:   Removing import PIL.ImageQt from module PyQt4.QtGui.QImage
17138 WARNING:   Removing import PIL.ImageQt from module PyQt4.QtCore
17138 WARNING:   Removing import PIL.ImageQt from module PyQt4.QtGui.QPixmap
17138 WARNING:   Removing import PIL.ImageQt from module PyQt4.QtCore.QIODevice
17138 WARNING:   Removing import PIL.ImageQt from module PyQt4.QtCore.QBuffer
17138 WARNING:   Removing import PIL.ImageQt from module PyQt4.QtGui.qRgba
17138 WARNING:   Removing import PIL.ImageQt from module PyQt4.QtGui
17138 INFO: Loading module hook "hook-gtk.py"...
17139 WARNING: Hidden import "gtkglext" not found!
17139 WARNING: Hidden import "gdkgl" not found!
17140 WARNING: Hidden import "gdkglext" not found!
17140 WARNING: Hidden import "gtk.gdk" not found!
17140 WARNING: Hidden import "gtk.gtkgl" not found!
17140 WARNING: Hidden import "gtk.gtkgl._gtkgl" not found!
17141 WARNING: Hidden import "gtkgl" not found!
17203 INFO: Loading module hook "hook-jinja2.py"...
17217 INFO: Loading module hook "hook-httplib2.py"...
17218 INFO: Loading module hook "hook-httplib.py"...
17218 INFO: Loading module hook "hook-sklearn.metrics.cluster.py"...
17221 INFO: Loading module hook "hook-pydoc.py"...
17225 INFO: Excluding import 'Tkinter'
17229 WARNING:   Removing import pydoc from module Tkinter
17229 INFO: Loading module hook "hook-PyQt4.py"...
17230 INFO: Loading module hook "hook-encodings.py"...
17467 INFO: Loading module hook "hook-reportlab.pdfbase._fontdata.py"...
17471 INFO: Loading module hook "hook-PyQt4.QtCore.py"...
17496 INFO: Loading module hook "hook-_tkinter.py"...
17563 INFO: checking Tree
17563 INFO: Building Tree because out00-Tree.toc is non existent
17563 INFO: Building Tree out00-Tree.toc
17599 INFO: checking Tree
17599 INFO: Building Tree because out01-Tree.toc is non existent
17599 INFO: Building Tree out01-Tree.toc
17613 INFO: Loading module hook "hook-matplotlib.backends.py"...
17999 INFO:   Matplotlib backend "GTK": added
18266 INFO:   Matplotlib backend "GTKAgg": added
18529 INFO:   Matplotlib backend "GTKCairo": added
18748 INFO:   Matplotlib backend "MacOSX": ignored
    cannot import name _macosx
18994 INFO:   Matplotlib backend "Qt4Agg": added
19242 INFO:   Matplotlib backend "Qt5Agg": added
19484 INFO:   Matplotlib backend "TkAgg": added
19697 INFO:   Matplotlib backend "WX": ignored
    Matplotlib backend_wx and backend_wxagg require wxPython >=2.8.12
19909 INFO:   Matplotlib backend "WXAgg": ignored
    Matplotlib backend_wx and backend_wxagg require wxPython >=2.8.12
20022 INFO:   Matplotlib backend "GTK3Cairo": ignored
    Gtk3 backend requires pygobject to be installed.
20239 INFO:   Matplotlib backend "GTK3Agg": ignored
    Gtk3 backend requires pygobject to be installed.
20353 INFO:   Matplotlib backend "WebAgg": ignored
    Traceback (most recent call last):
  File "<string>", line 12, in <module>
  File "/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_webagg.py", line 30, in <module>
    raise RuntimeError("The WebAgg backend requires Tornado.")
RuntimeError: The WebAgg backend requires Tornado.
20473 INFO:   Matplotlib backend "nbAgg": ignored
    No module named tornado.ioloop
20682 INFO:   Matplotlib backend "agg": added
20898 INFO:   Matplotlib backend "cairo": added
21015 INFO:   Matplotlib backend "emf": ignored
    No module named backend_emf
21273 INFO:   Matplotlib backend "gdk": added
21488 INFO:   Matplotlib backend "pdf": added
21717 INFO:   Matplotlib backend "pgf": added
21933 INFO:   Matplotlib backend "ps": added
22152 INFO:   Matplotlib backend "svg": added
22365 INFO:   Matplotlib backend "template": added
22670 INFO: Loading module hook "hook-PIL.Image.py"...
22837 INFO: Loading module hook "hook-matplotlib.py"...
22953 INFO: Loading module hook "hook-PyQt4.QtGui.py"...
23084 INFO: Loading module hook "hook-PyQt4.QtNetwork.py"...
23109 INFO: Loading module hook "hook-pkg_resources.py"...
23360 INFO: Processing pre-safe import module hook   win32com
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ImportError: No module named win32com
23375 INFO: Processing pre-safe import module hook   win32com
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ImportError: No module named win32com
23391 INFO: Processing pre-safe import module hook   win32com
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ImportError: No module named win32com
23409 INFO: Processing pre-safe import module hook   win32com
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ImportError: No module named win32com
23428 INFO: Loading module hook "hook-scipy.linalg.py"...
23428 INFO: Loading module hook "hook-scipy.sparse.csgraph.py"...
23431 INFO: Loading module hook "hook-pytz.py"...
23432 INFO: Loading module hook "hook-setuptools.py"...
23432 INFO: Loading module hook "hook-scipy.special._ellip_harm_2.py"...
23432 INFO: Loading module hook "hook-PIL.SpiderImagePlugin.py"...
23439 INFO: Excluding import 'FixTk'
23443 INFO: Excluding import 'Tkinter'
23447 INFO: Loading module hook "hook-sqlalchemy.py"...
23573 INFO:   Found 4 sqlalchemy hidden imports
23574 WARNING: Hidden import "pysqlite2" not found!
23574 WARNING: Hidden import "MySQLdb" not found!
24221 WARNING: Hidden import "sqlalchemy.sql.functions.func" not found!
24226 INFO: Import to be excluded not found: 'sqlalchemy.testing'
24226 INFO: Loading module hook "hook-sqlite3.py"...
24227 INFO: Loading module hook "hook-scipy.special._ufuncs.py"...
24228 INFO: Loading module hook "hook-PyQt4.QtXml.py"...
24228 INFO: Loading module hook "hook-reportlab.lib.utils.py"...
24231 INFO: Loading module hook "hook-psycopg2.py"...
24364 INFO: Looking for ctypes DLLs
24481 INFO: Analyzing run-time hooks ...
24502 INFO: Including run-time hook 'pyi_rth_mplconfig.py'
24503 INFO: Including run-time hook 'pyi_rth_mpldata.py'
24504 INFO: Including run-time hook 'pyi_rth_pkgres.py'
24505 INFO: Including run-time hook 'pyi_rth_qt4plugins.py'
24506 INFO: Including run-time hook 'pyi_rth__tkinter.py'
24545 INFO: Looking for dynamic libraries
27855 INFO: Looking for eggs
27855 INFO: Python library not in binary depedencies. Doing additional searching...
27885 INFO: Using Python library /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
27938 INFO: Warnings written to /home/*****/Dropbox/mypythonfiles/build/mycluster/warnmycluster.txt
28268 INFO: checking PYZ
28268 INFO: Building PYZ because out00-PYZ.toc is non existent
28268 INFO: Building PYZ (ZlibArchive) /home/*****/Dropbox/mypythonfiles/build/mycluster/out00-PYZ.pyz
30348 INFO: checking PKG
30348 INFO: Building PKG because out00-PKG.toc is non existent
30348 INFO: Building PKG (CArchive) out00-PKG.pkg
102269 INFO: Bootloader /usr/local/lib/python2.7/dist-packages/PyInstaller/bootloader/Linux-64bit/run
102269 INFO: checking EXE
102269 INFO: Building EXE because out00-EXE.toc is non existent
102269 INFO: Building EXE from out00-EXE.toc
102269 INFO: Appending archive to ELF section in EXE /home/*****/Dropbox/mypythonfiles/dist/mycluster
*****@*****:~/Dropbox/mypythonfiles$ cd dist*****@*****:~/Dropbox/mypythonfiles/dist$ ./myclusterTraceback (most recent call last):
  File "mycluster.py", line 39, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "clustering_algorithms.py", line 9, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "sklearn/cluster/__init__.py", line 6, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "sklearn/cluster/spectral.py", line 17, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "sklearn/neighbors/__init__.py", line 6, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 546, in load_module
    module = imp.load_module(fullname, fp, filename, ext_tuple)
  File "sklearn/neighbors/dist_metrics.pxd", line 48, in init sklearn.neighbors.ball_tree (sklearn/neighbors/ball_tree.c:36366)
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 546, in load_module
    module = imp.load_module(fullname, fp, filename, ext_tuple)
  File "sklearn/neighbors/dist_metrics.pyx", line 52, in init sklearn.neighbors.dist_metrics (sklearn/neighbors/dist_metrics.c:27473)
ImportError: No module named typedefs
Failed to execute script mycluster
ilitse
  • 127
  • 2
  • 10
  • 1
    Did `from PyQt4 import QtCore, QtGui` work? You should run your "frozen" application in command line and report the exact error. – Repiklis Sep 22 '16 at 14:24
  • It kind of did I think but it kept asking me for new modules such as QtNetwork and Qsci. I edited my question and added the exact error screen. – ilitse Sep 22 '16 at 15:30
  • This is not related to PyQt4, but it is better to remove the duplicate import statements. Even though your error seems to occur while building (a but confusing to be honest), you can try adding `--hidden-import sklearn.neighbors.typedefs` when calling `pyinstaller` as suggested [here](http://stackoverflow.com/questions/31774906/why-do-i-get-an-importerror-when-building-a-exe-with-pyinstaller). – Repiklis Sep 22 '16 at 16:10

0 Answers0