M. Mariscal
M. Mariscal

Reputation: 1328

How to use PyInstaller with multiple .py?

I'm trying to do some hybrid app (Mac, Windos, Linux OS) with Pyinstaller on Ubuntu 17.10, but when I do:

pyinstaller XXX.py 

It generates everything correctly but cannot execute the program (Made with PyQT4 7 Python2.7). The program contains the main.py & file.py & file.ui, What should I do to test the executable? When I run the file inside /dist or /build, it didn't do anything.

LOG

82 INFO: PyInstaller: 3.3 82 INFO: Python: 2.7.14 83 INFO: Platform: Linux-4.13.0-16-generic-x86_64-with-Ubuntu-17.10-artful 83 INFO: wrote /home/manel/Documentos/PythonProject/GUI.spec 85 INFO: UPX is not available. 86 INFO: Extending PYTHONPATH with paths ['/home/manel/Documentos/PythonProject', '/home/manel/Documentos/PythonProject'] 86 INFO: checking Analysis 86 INFO: Building Analysis because out00-Analysis.toc is non existent 87 INFO: Initializing module dependency graph... 88 INFO: Initializing module graph hooks... 117 INFO: running Analysis out00-Analysis.toc 129 INFO: Caching module hooks... 131 INFO: Analyzing /home/manel/Documentos/PythonProject/GUI.py 960 INFO: Processing pre-safe import module hook _xmlplus 2511 INFO: Processing pre-find module path hook distutils 2834 INFO: Processing pre-find module path hook PyQt4.uic.port_v3 2835 INFO: Processing pre-find module path hook PyQt4.uic.port_v2 2963 INFO: Loading module hooks... 2963 INFO: Loading module hook "hook-distutils.py"... 2963 INFO: Loading module hook "hook-sysconfig.py"... 2964 INFO: Loading module hook "hook-xml.py"... 3001 INFO: Loading module hook "hook-gtk.py"... 3002 WARNING: Hidden import "gtkglext" not found! 3002 WARNING: Hidden import "gdkgl" not found! 3003 WARNING: Hidden import "gdkglext" not found! 3003 WARNING: Hidden import "gtk.gdk" not found! 3003 WARNING: Hidden import "gtk.gtkgl" not found! 3003 WARNING: Hidden import "gtk.gtkgl._gtkgl" not found! 3004 WARNING: Hidden import "gtkgl" not found! 3046 INFO: Loading module hook "hook-lxml.etree.py"... 3047 INFO: Loading module hook "hook-httplib.py"... 3047 INFO: Loading module hook "hook-PyQt4.py"... 3048 INFO: Loading module hook "hook-PyQt4.uic.py"... 3049 INFO: Loading module hook "hook-PyQt4.QtGui.py"... 3130 INFO: Loading module hook "hook-PyQt4.QtSvg.py"... 3130 INFO: Loading module hook "hook-encodings.py"... 3393 INFO: Loading module hook "hook-PyQt4.QtCore.py"... 3410 INFO: Loading module hook "hook-PyQt4.QtXml.py"... 3417 INFO: Looking for ctypes DLLs 3474 WARNING: library msvcrt required via ctypes not found 3474 INFO: Analyzing run-time hooks ... 3477 INFO: Including run-time hook 'pyi_rth_qt4plugins.py' 3482 INFO: Looking for dynamic libraries 4831 INFO: Looking for eggs 4831 INFO: Python library not in binary dependencies. Doing additional searching... 4860 INFO: Using Python library /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 4869 INFO: Warnings written to /home/manel/Documentos/PythonProject/build/GUI/warnGUI.txt 4906 INFO: Graph cross-reference written to /home/manel/Documentos/PythonProject/build/GUI/xref-GUI.html 4956 INFO: checking PYZ 4956 INFO: Building PYZ because out00-PYZ.toc is non existent 4956 INFO: Building PYZ (ZlibArchive) /home/manel/Documentos/PythonProject/build/GUI/out00-PYZ.pyz 5244 INFO: Building PYZ (ZlibArchive) /home/manel/Documentos/PythonProject/build/GUI/out00-PYZ.pyz completed successfully. 5279 INFO: checking PKG 5279 INFO: Building PKG because out00-PKG.toc is non existent 5280 INFO: Building PKG (CArchive) out00-PKG.pkg 5294 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully. 5295 INFO: Bootloader /usr/local/lib/python2.7/dist-packages/PyInstaller/bootloader/Linux-64bit/run 5295 INFO: checking EXE 5296 INFO: Building EXE because out00-EXE.toc is non existent 5296 INFO: Building EXE from out00-EXE.toc 5296 INFO: Appending archive to ELF section in EXE /home/manel/Documentos/PythonProject/build/GUI/GUI 5300 INFO: Building EXE from out00-EXE.toc completed successfully. 5301 INFO: checking COLLECT 5301 INFO: Building COLLECT because out00-COLLECT.toc is non existent 5301 INFO: Building COLLECT out00-COLLECT.toc 5394 INFO: Building COLLECT out00-COLLECT.toc completed successfully.

Thanks anyway

Upvotes: 0

Views: 2661

Answers (2)

apogalacticon
apogalacticon

Reputation: 789

I think that @giantas is suggesting that you run the .app (or .exe) file from the terminal (or command prompt), not to run the .py file. /path/to/app/dist/MyApp.app/Contents/MacOS/MyApp for Mac (in Terminal), /path/to/app/dist/MyApp.exe for Windows (in Command Prompt). This will allow you to observe any errors that may exist after the app was bundled.

It sounds like you are not including the additional data files in the bundle. You can add other .py or data files to the application by adding them to the datas list in the PyInstaller .spec file that should have been generated the first time you ran PyInstaller on this application:

....
added_files = [
          ('your_ui_file.ui', '.'),
          ('Icons\\', 'Icons\\')
          ]
a = Analysis(['main.py'],
         pathex=['C:\\Users\\your_name\\wherever\\main.py\\lives'],
         binaries=[],
         datas=added_files,
         hiddenimports=['list.of.hidden.imports'],
....

This is also explained in the PyInstaller docs. If your main application imports other .py files, they should not need to be included in the datas list.

You may also need to consider the directory that these files are saved in during the bundling process. Check out this post for a more comprehensive discussion on how to properly call data files from your executable.

Alternatively, you may be able to just copy the .ui file to the dist directory, where the executable lives.

Upvotes: 0

omushpapa
omushpapa

Reputation: 1732

Probably one of the files is raising an error. The best way to handle this is to try and run the app from the command line. This will show you the errors, if any. Just open the terminal cd into the dist directory then type main

Upvotes: 1

Related Questions