Application fails to start after building using cx_Freeze on OSX - python

I'm trying to build a simple app on OSX using cx_Freeze. The build using setup.py seems to go fine - it builds a .dmg and .app for my application, along with all of the source files. However, when I try to run the .app, it crashes immediately, saying "My_App quit unexpectedly". Frustratingly, I don't see any decipherable error codes I can track down.
I have stripped down the app into a very simple example. Below are my main python file and my setup file.
my_app.py
from tkinter import *
root = Tk()
root.title("Welcome to My_App")
root.geometry('350x200')
root.mainloop()
setup.py
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": [], "excludes": []}
# base="Win32GUI" should be used only for Windows GUI app
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(
name = "My_GUI",
version = "1.0",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("my_app.py", base=base)]
)
I have built an .exe on windows before, and when startup fails on windows, I at least get a traceback error message that I can track down. On OSX, it doesn't appear to do the same thing.
What's going wrong? How can I get more information on why my app is failing to start up? Below are images of my build and the error I'm getting on startup.

Ok turns out if I run the file from terminal, it outputs an actual error code. From there, I was able to track down that I did not have zlib installed. I was getting error
zipimport.ZipImportError: can't decompress data; zlib not available
What ultimately solved it for me was reading through this thread
https://github.com/jiansoung/issues-list/issues/13

Related

Problems packaging PyQt application (including QML) using cx_freeze

I'm attempting to package a PyQt application using cx_freeze. I'm running Python 3.4, Qt 5.6, PyQt 5.5.1 and Cx_freeze 4.3.4 on Windows 7.
There are three pieces to my application, the python/PyQt code, a Qt UI file which contains the GUI elements, and a QML file which runs an interactive map similar to the places_map.qml example. The QML file using the osm map plugin.
My Qt UI file includes a QQuickWidget whose source is the QML file. I'm attempting to package the application, so that others can run it without installing python and Qt. I've created a custom setup.py scripts for cx_freeze to use. However, I keep encountering various ImportErrors related to the QQuickWidget when running my built Exe files. The error occurs when my Python code loads the UI file. I've attempted to include pretty much anything related to QQuickWidgets and the QML code that I can think of in my setup.py file. Initially, the ImportError was missing QQuickWidgets. After adding the SIP QQuickWidget files, the error is now related to QQuickWidgets.QQuickWidget. Below is my setup.py file.
from cx_Freeze import setup, Executable
import os
PYQT5_DIR = "c:/Python34/lib/site-packages/PyQt5/"
include_files = ['TTRMS.ui','places_map.qml',
(os.path.join(PYQT5_DIR, "qml", "QtQuick.2"), "QtQuick.2"),
(os.path.join(PYQT5_DIR, "qml", "QtQuick"), "QtQuick"),
(os.path.join(PYQT5_DIR, "qml", "QtQml"), "QtQml"),
(os.path.join(PYQT5_DIR, "qml", "Qt"), "Qt"),
(os.path.join(PYQT5_DIR, "qml", "QtPositioning"), "QtPositioning"),
(os.path.join(PYQT5_DIR, "qml", "QtLocation"), "QtLocation"),'C:/Python34/Lib/site-packages/PyQt5/uic/widget-plugins',
'C:/Python34/Lib/site-packages/PyQt5/plugins/geoservices','C:/Python34/Lib/site-packages/PyQt5/sip/PyQt5/QtQuickWidgets',
'C:/Python34/Lib/site-packages/PyQt5/sip/PyQt5/QtQuick']
buildOptions = dict(packages = ['PyQt5.QtQuickWidgets',"atexit","sip","PyQt5.QtCore","PyQt5.QtGui","PyQt5.QtWidgets",
"PyQt5.QtNetwork","PyQt5.QtOpenGL", "PyQt5.QtQml", "PyQt5.QtQuick"],
excludes = [], includes = ["atexit","re"], include_files = include_files)
import sys
base = 'Win32GUI' if sys.platform=='win32' else None
executables = [
Executable('Main.py', base=base, targetName = 'main.exe')
]
setup(name='TTRMS',
version = '1.0',
description = 'Travel Time Reliability',
options = dict(build_exe = buildOptions),
executables = executables)
Here is the error when running my Exe:
I'm not sure what else I need to include in my setup.py in order to package the application properly. I've successfully packaged a small PyQt app with a UI file, but never a UI file which then imports QML through a QQuickWidget. I'm not very knowledgeable about Qt either, so this whole process is new to me. Please let me know if you have any suggestions and let me know if I need to clarify anything. I appreciate any help!

.exe created with cxfreeze-quickstart does nothing - cx_freeze 5.0

I am using python 3.5.1 and the unofficial cx_freeze 5.0 build available from here. I am trying to create an executable version of a python project using tkinter and sympy that I've been working on. I used cxfreeze-quickstart to create a setup.py file for the program, and in terms of building what at least seems to be a valid executable, it works without throwing any errors. However, when I try to run the executable, nothing happens. I know similar questions have been asked on here and I've looked at and tried to understand every one I've found, but none of the solutions have worked for me. I don't understand what's going on, and any help would be appreciated. Code below:
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = [], excludes = [])
import sys
base = 'Win32GUI' if sys.platform=='win32' else None
executables = [
Executable('c:\\users\\joe\\pycharmprojects\\physics2-0\\physics2-0.py', base=base,
targetName = 'c:\\users\\joe\\pycharmprojects\\physics2-0\\physics.exe')
]
setup(name='physics solver',
version = '0.1',
description = 'alpha physics solver',
options = dict(build_exe = buildOptions),
executables = executables)
Thanks in advance.
UPDATE: I am now attempting to write the setup.py script myself according to the template provided in the docs, although any help would still be greatly appreciated.
UPDATE 2: I wrote my own setup.py according to the template provided in the docs, and put it in the same folder as the script I want to freeze, something I hadn't realized I needed to do. I ran python setup.py build in command line, and it created the build subdirectory with the exe and DLLs. However, now when I try and run the exe, an error message pops up that says ImportError: DLL load failed. The specified module could not be found. in reference to tkinter. The code for the 2nd setup.py is below.
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["tkinter", "sympy", "_tkinter"], "excludes": []}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == 'win32':
base = "Win32GUI"
setup( name = "physics solver",
version = "0.1",
description = "a basic physics solver",
options = {"build_exe": build_exe_options},
executables = [Executable("Physics2-0.py", base=base)])
Below are the first 4 lines of physics2-0.py. The line brought into question by the error message is line 1.
from tkinter import *
from tkinter import ttk
from sympy import Symbol
from sympy.solvers import solve
UPDATE 3: Someone please help me out here. I can't figure this out. I've even done a clean re-install of python at this point, just to be sure I didn't accidentally mess something up at some point, and it's still giving me the same error message.

cx_freeze: Not a directory

I'm trying to create a binary on Linux (Manjaro Linux, x86_64, python 3.4).
My app is a GUI software, written with PyQt.
Here is my setup.py:
import sys
import os
from cx_Freeze import setup, Executable
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
base = "Win32GUI"
my_data_files = ["./images/", "./journals/", "./config/"]
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"],
"excludes": [
"tkinter"
],
'includes': [
'sip',
'PyQt4.QtCore',
'PyQt4.QtGui',
'PyQt4.QtNetwork',
'PyQt4.QtSql',
'scipy.sparse.csgraph._validation',
'sklearn.utils.sparsetools._graph_validation',
'scipy.special._ufuncs_cxx'
],
'include_files': my_data_files
}
setup(name = "guifoo",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("gui.py", base=base)])
For now, I'm just starting. The "includes" part in the options is what I used when I compiled my binary with py2exe (it worked, but I want a unique tool to compile for all the platforms).
When I start the compilation with
python setup.py build
everything seems to work fine, but when I try to start the binary, I have this exception:
NotADirectoryError: [Errno 20] Not a directory: '/home/djipey/Desktop/test/build/exe.linux-x86_64-3.4/library.zip/text_unidecode/data.bin'
So I assume I have a problem with the module text_unidecode, but I can't really identify what the problem is.
Could you give me a hand please ?
EDIT:
Ok, sorry for the lack of precision, I didn't copy/paste the whole error message:
File "/usr/lib/python3.4/site-packages/text_unidecode/__init__.py", line 6, in <module>
with open(_data_path, 'rb') as f:
NotADirectoryError: [Errno 20] Not a directory: '/home/djipey/Desktop/test/build/exe.linux-x86_64-3.4/library.zip/text_unidecode/data.bin'
I think the issue can come from text_unidecode, but I don't know why. I installed it without any problem on my computer.
https://github.com/kmike/text-unidecode/blob/master/src/text_unidecode/init.py
EDIT 2:
If I integrate the code of text-unidecode (it is basically a single function) in my own code, it works. I think I know why I have this issue. In text-unidecode, there is a file called "data.bin" which contains data used by the function of text-unidecode. It is a part of the library, but it is not added to library.zip when I use cx_freeze. So text-unidecode can't work.
Is there an elegant way to solve this with cx_freeze ? Like an option, to add data files to library.zip ?

Working with cx_Freeze - how to include all necessary files in .exe?

I want to make a self-contained .exe file.
I have managed to use cx_Freeze to build one that works on my machine, but it is throwing an error about needing the .dlls when I sent it to someone. I read a few of the similar questions, which is how I ended up including packages in the build options.
I suspect that once I get past this particular problem, I will end up needing to include other stuff in the .exe....any help getting around that pitfall is appreciated! The end user needs to be able to only use the .exe and not have to install other files.
Here is my current setup.py:
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
build_options = {"includes" : [ "re", "atexit"], "packages": ["PyQt4.QtCore", "PyQt4.QtGui"]}
setup( name = "Hex Script Combination",
version = "0.1",
description = "Contact (info) with questions",
options = {"build_exe" : build_options},
executables = [Executable("Project.py", base=base)])
ETA:
I tried IExpress, and I'm running into this error:
(Picture uploaded but for some reason, neither picture in this post is showing)
File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in <module>
code = importer.get_code(moduleName)
ZipImportError: can't find module 'projec~1__main__'
I did NOT find a way to do exactly what I wanted. I did, however, discover that I was getting an installer I wasn't aware of for distribution that did install everything that was in my exe directory.
File path was ~\dist, and it contained only an .msi file. Launching it installed everything that was in ~\build\exe.win32-2.7

How can I hide the console window when freezing wxPython applications with cxFreeze?

I'm developing a Python application using wxPython and freezing it using cxFreeze. All seems to be going fine apart from this following bit:
When I run the executable created by cxFreeze, a blank console window pops up. I don't want to show it. Is there any way I could hide it?
It doesn't seem to be documented on the cxFreeze site and Googling didn't turn up much apart from some similar sorta problems with Py2Exe.
Thanks.
For Windows:
You have to use a line like this (use file folders and names as appropriate)
C:/Python/Scripts/cxfreeze C:/Python/Code/yourprogram.py --base-name=Win32GUI --target-dir C:/Python/Dist
By adding the --base-name=Win32GUI option, the console window will not appear.
This worked to some extent but it has issues. My program runs in both a console mode and a GUI mode. When run from the console with a --console argument it runs in a console mode. When I followed the procedure below, this doesn't work anymore and my program is only a GUI app then.
The following source code comes from a sample file in the \Python\Lib\site-packages\cx_Freeze\samples\PyQt4\setup.py. Lesson of the day. Read the README.
# A simple setup script to create an executable using PyQt4. This also
# demonstrates the method for creating a Windows executable that does not have
# an associated console.
#
# PyQt4app.py is a very simple type of PyQt4 application
#
# Run the build process by running the command 'python setup.py build'
#
# If everything works well you should find a subdirectory in the build
# subdirectory that contains the files needed to run the application
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(
name = "simple_PyQt4",
version = "0.1",
description = "Sample cx_Freeze PyQt4 script",
executables = [Executable("PyQt4app.py", base = base)])
If you're using Windows, you could rename your "main" script's extension (that launches the app) to .pyw
Option 1) Use gui2exe to muck with various options.
Option 2) Modify your setup.py with 'base' parameter as such.
GUI2Exe_Target_1 = Executable(
# what to build
script = "rf_spi.py",
initScript = None,
base = 'Win32GUI', # <-- add this
targetDir = r"dist",
targetName = "rf_spi.exe",
compress = True,
copyDependentFiles = False,
appendScriptToExe = False,
appendScriptToLibrary = False,
icon = r"wireless.ico"
)

Categories

Resources