Packaging a PyQt5 app for Mac OS - python

I'm running into a problem trying to package a PyQt program as a Mac OS application.
I can create the app using cx_Freeze, but when I open the app it quits unexpectedly. In the console it shows the error that there are two versions Qt installed on the computer and it can't decide which one to use. One version is in the app I just made and the other is in /usr/local/Cellar/qt5/...
How do I get around this? The script works totally fine not packaged as an app.
EDIT:
Adding the errors and setup.py
Console readout:
objc[56464]: Class NotificationReceiver is implemented in both /path/to/the.app/Contents/MacOS/QtWidgets and /usr/local/Cellar/qt5/5.5.1_2/lib/QtWidgets.framework/Versions/5/QtWidgets. One of the two will be used. Which one is undefined.
objc[56464]: Class QCocoaPageLayoutDelegate is implemented in both /path/to/the.app/Contents/MacOS/QtPrintSupport and /usr/local/Cellar/qt5/5.5.1_2/lib/QtPrintSupport.framework/Versions/5/QtPrintSupport. One of the two will be used. Which one is undefined.
objc[56464]: Class QCocoaPrintPanelDelegate is implemented in both /path/to/the.app/Contents/MacOS/QtPrintSupport and /usr/local/Cellar/qt5/5.5.1_2/lib/QtPrintSupport.framework/Versions/5/QtPrintSupport. One of the two will be used. Which one is undefined.
setup.py:
from cx_Freeze import setup, Executable
import sys
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages=[], excludes=[])
base = 'Win32GUI' if sys.platform == 'win32' else None
executables = [
Executable('qt_test.py', base=base)
]
setup(
name='SpamEggs',
version='0.1',
description='The Description',
options=dict(build_exe=buildOptions),
executables=executables
)

Related

Python cx_Freeze import _tkinter and ImportError: DLL load failed %1 is not a valid win32 application ERROR

cx_Freeze import _tkinter #if this fails your python may not be configurated for Tk.. ImportError: DLL load failed: %1 is not a valid win32 application
Hi! I created a word guessing/memorizing language practice program in tkinter, and i wanted to convert it to an executable app but i get errors again and again... I tried at least 10-15 different ways but it is still same. So i googled all the similar topics and tried every single suggestion but they did not work for me. I tried pyinstaller as well. It does not give an error but also it does not run the executed app either. When i click on the app.exe, black CMD screen appears then disappears and it creates the csv file to save the words. So i changed to cx_Freeze but it does not work either.
What have i tried?
For pyinstaller:
I converted my app.py to app.exe by using pyinstaller -F app.py and pyinstaller app.py, but none of them worked.
For cx_Freeze
1- I tried my old setup.py (which worked to convert my all games to .exe) but it did not work on this, i guess it is about tkinter. Because my games were written with pygame, i did not use tkinter for anything.
2 -I tried at least 10 different setup files shared by you guys on stackoverflow and other websites. But they did not work either.
3- I tried to set environment
4- I tried to specify environment
5- I copied tcl86t.dll and tk86t.dll files from the python dlls to my app directory and added them as included files in the setup.py
6- I deleted 64bit version and i only have 32bit version of python3.7
and more and more...
So this is my current setup.py
import sys,os
from cx_Freeze import setup, Executable
os.environ['TCL_LIBRARY'] = "C:\Python37\tcl\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\Python37\tcl\tk8.6"
build_exe_options = {"packages": ["os"],"includes":["tkinter"],"include_files": []}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "App",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("app.py", base=base)]
)
I use Windows7 64bit and Python 3.7.1 32bit and 3.7.0 64bit
So what should i do? I am stuck here. I really gave up and asking a new question on here. Please help me guys.. Thanks in advance.

cx_freeze creates exe that requests admin rights

I am using cx_freeze 4.3.3 for python 3.3. It creates an exe file, but out of sudden, the created file asks for admin rights. This never happened before.
And I need it to create exe files that do not request admin rights.
Is there a reason why it is doing that? Or is there a way to set it up so the file won't request admin rights?
Here's the setup.py code:
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(
name = "QueueUpdate",
version = "1.6",
description = "Tracker for CRAP. Internally, our hamsters work very\
hard to keep track of your time. Be grateful and find a way to feed them.",
executables = [Executable("queueupdate2.py", base = base)]
)
Thank you

Py2exe compiles properly but the built application doesn't work

I am using Python 2.7 to build my application. Within it, I used few packages which are numpy, scipy, csv, sys, xlwt, time, wxpython and operator.
All the above packages are in 64-bit, and I am using python 2.7(64-bit version) in Aptana Studio 3(64-bit version) in Windows 7 Professional (64-bit version).
At last, I'd like to compile my project to an application using following code, the file name is py2exeTest.py:
from distutils.core import setup
import numpy # numpy is imported to deal with missing .dll file
import py2exe
setup(console=["Graphical_Interface.py"])
Then in cmd, I switched to the directory of the project and used following line to compile it:
python py2exeTest.py py2exe
Everything goes well, it generates an application under dist directory, and the application name is Graphical_Interface.exe.
I double clicked it, but there is a cmd window appears, and a python output windows flashes, then both of them disappeared. I tried to run the application as an administrator, the same outcome I've had.
May I know how to work this out?
Thanks!
EDIT:
I've managed to catch the error information that flashes on the screen. The error info I had is:
Traceback (most recent call last):
File "Graphical_Interface.py", line 397, in <module>
File "Graphical_Interface.py", line 136, in __init__
File "wx\_core.pyc", line 3369, in ConvertToBitmap
wx._core.PyAssertionError: C++ assertion "image.Ok()" failed at ..\..\src\msw\bitmap.cpp(802) in wxBitmap::CreateFromImage(): invalid image
I used one PNG image in the project, the code is like follows:
self.workflow = wx.Image("Work Flow.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
wx.StaticBitmap(self.panel_settings, -1, self.workflow, (330,270), (self.workflow.GetWidth(), self.workflow.GetHeight()))
I tried to comment the above chunk out from the project, and the application works properly. However, I need the image to show up in the application.
May I know how to deal with it?
Thanks.
Hiding console window of Python GUI app with py2exe
When compiling graphical applications you can not create them as a console application because reasons (honestly can't explain the specifics out of my head), but try this:
from distutils.core import setup
import numpy
import py2exe
import wxpython
setup(window=['Graphical_Interface.py'],
options={"py2exe" { 'boundle_files' : 1}})
Also consider changing to:
http://cx-freeze.sourceforge.net/
It works with Python3 and supports multiple platforms.
A cx_freeze script would look something like:
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
base = "Win32GUI"
includefiles = ['/folder/image.png']
setup( name = "GUIprog",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options, 'include_files' : includefiles},
executables = [Executable("Graphical_Interface.py", base=base)])
No worries, I've got the solution.
It turns out that the image is in the project folder rather than in the dist folder. So I have two solutions:
Copy the image into dist folder
Include the full path of the image in the code.
Thanks for your help.

cx_freeze + PyQt5 + python

I'm running in circles with a really strange thing happen. Basically I'm trying a simple window app with PyQt5+python3.3+cx_freeze4.3.2. The problem runs perfect calling the python:
python test.py
Now the second part the basic setup.py to the cx_freeze:
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
options = {
'build_exe': {
'includes': 'atexit'
}
}
executables = [
Executable('test.py', base=base)
]
setup(name='test',
version='0.1',
description='test',
options=options,
executables=executables
)
build it:
python test.py build
The follow folder is created:
build/exe.win32-3.3:
/platforms
/imageformats
test.exe
icudt49.dll
icuin49.dll
icuuc49.dll
libGLESv2.dll
library.zip
PyQt5.QtCore.pyd
PyQt5.QtGui.pyd
PyQt5.QtWidgets.pyd
python33.dll
Qt5Core.dll
Qt5Gui.dll
Qt5Widgets.dll
sip.pyd
unicodedata.pyd
_bz2.pyd
Now running test.exe everything works fine as it should.
The problem comes when I copy the build folder to other PC. An error pops-up when I run the test.exe
This application failed to start because it could not find or load the
QT platform plugin "windows".
Available platform plugin are: minimal, offscreen, windows.
Reinstalling the application may fix this problem
According everything I read it's about dlls on plataforms/ the .exe don't find qwindow.dll inside. Why it's only happen in other PC (win7)?? The developement PC (win7) works fine. To debug it and to have sure that qwindow.dll used is the one inside on plataforms/ I rename the folder to plataformFOO/ and try run the test.exe and now same problem in dev PC, so, the dll is in correct folder, rename it back to plataforms/ and everything working fine. Why the hell is not working in others PCs if the OS is the same and the folder is a simple copy of the one on dev PC.
I google, read loads of stuffs but can't figure out the problem. If someone can help ;)
I had the same problem and I'm running Anaconda 4.4.0 Python 2.7.13 using PyQt5 and cx_Freeze 5.0.1
Copy anaconda/library/plugin/platforms directory into the directory containing the .exe.
Run the executable and it should work

running a python script as administrator

i'm writing an installer using py2exe which needs to run in admin to have permission to perform various file operations. i've modified some sample code from the user_access_controls directory that comes with py2exe to create the setup file. creating/running the generated exe works fine when i run it on my own computer. however, when i try to run the exe on a computer that doesn't have python installed, i get an error saying that the import modules (shutil and os in this case) do not exist. it was my impression that py2exe automatically wraps all the file dependencies into the exe but i guess that this is not the case. py2exe does generate a zip file called library that contains all the python modules but apparently they are not used by the generated exe. basically my question is how do i get the imports to be included in the exe generated by py2exe. perhaps modification need to be made to my setup.py file - the code for this is as follows:
from distutils.core import setup
import py2exe
# The targets to build
# create a target that says nothing about UAC - On Python 2.6+, this
# should be identical to "asInvoker" below. However, for 2.5 and
# earlier it will force the app into compatibility mode (as no
# manifest will exist at all in the target.)
t1 = dict(script="findpath.py",
dest_base="findpath",
uac_info="requireAdministrator")
console = [t1]
# hack to make windows copies of them all too, but
# with '_w' on the tail of the executable.
windows = [{'script': "findpath.py",
'uac_info': "requireAdministrator",
},]
setup(
version = "0.5.0",
description = "py2exe user-access-control",
name = "py2exe samples",
# targets to build
windows = windows,
console = console,
)
Try to set options={'py2exe': {'bundle_files': 1}}, and zipfile = None in setup section. Python will make single .exe file without dependencies. Example:
from distutils.core import setup
import py2exe
setup(
console=['watt.py'],
options={'py2exe': {'bundle_files': 1}},
zipfile = None
)
I rewrite your setup script for you. This will work
from distutils.core import setup
import py2exe
# The targets to build
# create a target that says nothing about UAC - On Python 2.6+, this
# should be identical to "asInvoker" below. However, for 2.5 and
# earlier it will force the app into compatibility mode (as no
# manifest will exist at all in the target.)
t1 = dict(script="findpath.py",
dest_base="findpath",
uac_info="requireAdministrator")
console = [t1]
# hack to make windows copies of them all too, but
# with '_w' on the tail of the executable.
windows = [{'script': "findpath.py",
'uac_info': "requireAdministrator",
},]
setup(
version = "0.5.0",
description = "py2exe user-access-control",
name = "py2exe samples",
# targets to build
windows = windows,
console = console,
#the options is what you fail to include it will instruct py2exe to include these modules explicitly
options={"py2exe":
{"includes": ["sip","os","shutil"]}
}
)

Categories