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
Related
I have some simple cefpython code opening a url and am trying to create a stand alone executable with pyinstaller:
I copied files from https://github.com/cztomczak/cefpython/tree/master/examples/pyinstaller to a a directry named pyinstaller
I made following minor changes to pyinstaller.spec
+SECRET_CIPHER = ""
...
- ["../wxpython.py"],
+ ["../hello.py"],
...
- icon="../resources/wxpython.ico")
+ )
I can successfully compile my application on windows with python
On the same machine with python 3.5.4 64 bit and following virtualenv:
cefpython3==66.0
future==0.18.2
PyInstaller==3.2.1
pypiwin32==223
pywin32==228
I can also compile windows with python 3.6.4 64 and following virtualenv:
altgraph==0.17
cefpython3==66.0
future==0.18.2
macholib==1.14
pefile==2019.4.18
PyInstaller==3.3.1
pyinstaller-hooks-contrib==2020.9
pypiwin32==223
pywin32==228
pywin32-ctypes==0.2.0
On Linux compilation works as well, but the executable is not operational.
I get following output and error:
CEF Python 66.0
Chromium 66.0.3359.181
CEF 3.3359.1774.gd49d25f
Python 3.5.2 64bit
[1013/180954.001980:ERROR:icu_util.cc(133)] Invalid file descriptor to ICU data received.
Trace/breakpoint trap (core dumped)
version is python 3.5.2 64bit and the virtualenv is:
cefpython3==66.0
pkg-resources==0.0.0
PyInstaller==3.2.1
What could be the cause?
The code, that I try to compile is below:
import platform
import sys
from cefpython3 import cefpython as cef
def check_versions():
ver = cef.GetVersion()
print("CEF Python {ver}".format(ver=ver["version"]))
print("Chromium {ver}".format(ver=ver["chrome_version"]))
print("CEF {ver}".format(ver=ver["cef_version"]))
print("Python {ver} {arch}".format(
ver=platform.python_version(),
arch=platform.architecture()[0]))
assert cef.__version__ >= "57.0", "CEF Python v57.0+ required to run this"
def main(url="https://www.stackoverflow.com"):
sys.excepthook = cef.ExceptHook
check_versions()
settings = {}
switches = {}
browser_settings = {}
cef.Initialize(settings=settings, switches=switches)
cef.CreateBrowserSync(
url=url,
window_title="CEF_HELLO: ",
settings=browser_settings,
)
cef.MessageLoop()
cef.Shutdown()
if __name__ == "__main__":
main()
Addendum: 2020-10-14:
same error on linux with other versions:
so far I tried python 3.5 and 3.7
Is there anybody who successfully created an executable?
I could be, that this just an issue with the example project and its configuration?
As alternative, a solution could be found in PyInstaller bug 5400
Here the steps:
1- download the PyInstaller helper in CEFpython named hook-cefpython3.py from:
https://github.com/cztomczak/cefpython/tree/master/examples/pyinstaller and put in the root directory of your project
2- In that file, replace the line:
from PyInstaller.compat import is_win, is_darwin, is_linux, is_py2
with:
from PyInstaller.compat import is_win, is_darwin, is_linux
is_py2 = False
3- in your PyInstaller .spec file, add the '.' to the hookspath, e.g. hookspath=['.']. I think it is also possible to add it as PyInstaller command line option.
These steps should solve the problem, until CEFPython deliver a correct version of the hook file.
This is not really the answer I would like to accept, but it is at least one solution and contains information, that might lead to a better fix, a better answer.
After debugging with strace I found out, that the executable searches many files like for example icudtl.dat, v8_context_snapshot.bin, locales/* were searched in
'dist/cefapp/cefpython3but were copied todist/cefapp/`
An ugly work around is to do following after compilation
cd dist/cefapp/cefpython3
ln -s ../* .
and the executable works.
I'm sure there is also a nicer non-brute-force solution, but for the time being I wanted to answer in case others are stuck as well
Probably this can be fixed in the spec file but would we need one spec file for linux and one for windows then?
Perhaps there's also an option to tell the excutable to search for these files one level higer?
To solve this, you need to set this in your spec file:
hookspath=[r'YOUR_ENV_SITE_PACKAGES\cefpython3\examples\pyinstaller\']
And then rebuild, you will have things in the right place.
The following steps solved the issue for me on Windows 10, Python 3.9.5 32-bit, PyInstaller 4.3, and CEFPython 66.1:
Download the hook-cefpython3.py file from here and put it into your project root directory.
Run the pyinstaller command as usual but add the --additional-hooks-dir . command line option, so the command will look like this:
pyinstaller --additional-hooks-dir . <main-file.py>
As opposed to other answers here, this anser neither requires changes of hookspath directive in pyinstaller's spec file and, as of now, nor any changes to the downloaded hook-cefpython3.py file.
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.
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
)
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.
What I'm trying to do is compile a program I've written in Python 2.7, using pygame, into a standalone app for Mac computers. I'm working on a PC running Windows 8 with no access to a mac, so tweaking the process has been difficult.
When I run the setup file from the command prompt, I get the "text flood" (similar to what py2exe gave me when it worked to compile the windows version) and the program appears to work. It creates build and dist folders, but the dist folder has no contents. When looking at the command prompt output, the last two lines are
BASE_CFLAGS = cfg['CFLAGS']
Key Error: 'CFLAGS'
This seems to happen when py2app is trying to create the application bundle.
Here is the setup.py file I've gotten to thus far:
"""
Script for building the example.
Usage:
python setup.py py2app
"""
from setuptools import setup
NAME = 'PetCute Slide Puzzle Test'
VERSION = '0'
plist = dict(
CFBundleIconFile=NAME,
CFBundleName=NAME,
CFBundleShortVersionString=VERSION,
CFBundleGetInfoString=' '.join([NAME, VERSION]),
CFBundleExecutable=NAME,
CFBundleIdentifier='Py2App and PyGam test',
)
setup(
data_files=['Dog1.jpg', 'Dog2.jpg', 'Dog3.jpg', 'Dog4.jpg', 'Dog5.jp', 'Dog6.jpg', 'Dog7.jpg', 'Dog8.jpg', 'Dog9.jpg', 'Dog10.jpg', 'Dog11.jpg', 'Dog12.jpg', 'Dog13.jpg', 'Dog14.jpg', 'Dog15.jpg', 'Dog16.jpg', 'AYearWithoutRain.ttf'],
app=[
dict(script="PetCute_slidepuzzle.py", plist=plist),
],
setup_requires=["py2app"],
)
The data_files lists out the pictures and text file that need to be bundled with the code. I got to this by adapting the alien.py example. Please let me know if any more info is needed!
It probably had an error during compilation. I suggest you make sure you have Numpy installed, its needed for py2app to compile Pygame programs.