Mac cxFreeze app quits unexpectedly when trying to open - python

I am trying to convert a python script to a mac app so I can distribute it. I'm using cxFreeze to do this. After creating the app, I try to open it but it says the app quit unexpectedly and shows some report.
(code signature invalid (errno=1)
usr/local/lib/Python (no such file)
---
my script at.py:
import tkinter as tk
from tkinter import font
window = tk.Tk()
width=1
window.title('test')
window.geometry("425x500")
label_speed = tk.Label(
text="Speed"
)
label_speed.grid(row=1, column=1, columnspan = 5, stick="w")
window.mainloop()
And then my setup.py
from cx_Freeze import Executable, setup
base = None
if sys.platform == "win32":
base = "Win32GUI"
executables = [Executable("at.py", base=base)]
setup(
name="test",
version="0.1",
description="just for testing",
executables=executables,
)
I used the following commands to make the mac bundle or app.
python3 setup.py build then
python3 setup.py bdist_dmg
I had to use python3 instead of python because it wasn't working for me.
Thanks in advance for any tips and answers

There might be two different things going on. The first thing I know I have run into with cx_freeze is that it tried to map to where it thinks the python 2.x folder should be even if I specify to run on python 3.x. The other thing might be it was downloaded on to a different path. type $ where python to see where the file path should be. If you do $ open $FILEPATH and you see that its using python3 it might be worth reaching out to the maintainer of cx_freeze and see if they have any advice.

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.

error: [Errno 2] No such file or directory: '/Library/Frameworks/Tcl.framework/Versions/8.5/Tcl'

I made a tkinter app on my mac which runs well, when I run it from the terminal. Now, I want to make an executable version of it, but I get this error message after python setup.py build:
error: [Errno 2] No such file or directory: '/Library/Frameworks/Tcl.framework/Versions/8.5/Tcl'
setup.py:
import cx_Freeze, sys
import os
import os
os.environ['TCL_LIBRARY'] = "/System/Library/tcl/8.4"
base = None
if sys.platform == 'Win32':
base = "Win32GUI"
executables = [cx_Freeze.Executable("multiframe.py", base=base)]
cx_Freeze.setup(
name="cu",
options = {"build_exe": {"packages":["tkinter"]}},
version= "0.01",
description = "dasdasd",
executables = executables
)
I know that something is wrong with the tcl import but I have tcl in Python3.6 folder on windows but I don't in mac
In your options statement, you tell the system to import the "tkinter" package. "tkinter" is Python 3. "Tkinter" is for Python 2. If you are running Python 2 on your Mac, you need to use "Tkinter" instead of "tkinter" for a package. And, of course, you'll need to make sure your "cu" app runs on Python 2.
Also, the line
os.environ['TCL_LIBRARY'] = "/System/Library/tcl/8.4"
points to an old version of Tcl. Probably doesn't matter. But the later Python 2.7 and Python 3 both come with 8.5. You should probably upgrade your Mac to Python 3 to be the same as your Windows machine, so that your code will run in both places. Otherwise you may need little tweaks in your code to get the same code to run on both.

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.

Using cx_Freeze to Make First Program Into exe File

I made my first program (a gui calculator) in python using tkinter and am trying to use cx_freeze to turn it into an exe file. I'm really confused in how it works thought. I used cxfreeze quickstart in the scripts section of python33 to make my setup file. The program is named Calculator
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = [], excludes = [])
executables = [
Executable('Calculator.py', 'Win32GUI')
]
setup(name='Calculator',
version = '1.0',
description = '',
options = dict(build_exe = buildOptions),
executables = executables)
When I got to the console and type python setup.py build I get the error:
cx_Freeze.freezer.ConfigError: no initscript named Win32GUI
can anyone recommend a tutorial for using cx_Freeze or any other programs to make python code as exe format?
I suggest you try PyInstaller.
To convert a script to an exe file, you'd have to type something like this in a command prompt:
/path/to/python/pythonX.Y pyinstaller.py --onefile /path/to/your/script.py
Simple as that.

Py2app keyflag error CFLAGS

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.

Categories