Help building a mac application from python using py2app? - python

I have a Tkinter app written in python, and I want to make "native" (easy to run) mac and windows executables of it. I've successfully built a windows .exe using py2exe, but the equivalent process with py2app isn't working.
Here's my setup.py:
from setuptools import setup
import sys
MAIN_SCRIPT = "myapp.py"
WINDOWS_ICON = "myicon.ico"
MAC_ICON = "myicon.icns"
if sys.platform in ("win32", "win64"): # does win64 exist?
import py2exe
setup( windows=[{ "script":MAIN_SCRIPT,
"icon_resources":[(0x0004, WINDOWS_ICON)]
}],
)
elif sys.platform == "darwin":
import py2app
setup( app=[MAIN_SCRIPT], # doesn't include the icon yet
setup_requires=["py2app"],
)
I just cd to my app directory and run python setup.py py2app. The .app appears without errors, but it crashes on launch with "myapp has encountered a fatal error, and will now terminate."
I'm running Snow Leopard, and I've tried this with both the standard Apple Python 2.6 and python25 from MacPorts. I read somewhere that it's better to use a different Python because py2app won't bundle the system version in your app.
EDIT: Here's what the mac console has to say about it:
11/27/10 1:54:44 PM [0x0-0x80080].org.pythonmac.unspecified.myapp[77495] dlsym(0x10b120, Py_SetProgramName): symbol not found
11/27/10 1:54:46 PM [0x0-0x80080].org.pythonmac.unspecified.myapp[77495] 0x99274242
11/27/10 1:54:46 PM com.apple.launchd.peruser.501[185] ([0x0-0x80080].org.pythonmac.unspecified.myapp[77495]) Exited with exit code: 255

Turns out it was a problem with using Snow Leopard. I tried it on a Leopard machine at school and it builds fine.

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.

Command-line application using setuptools and Anaconda Python

I have a Python command line application that I have been distributing on PyPI in the manner described here: https://gehrcke.de/2014/02/distributing-a-python-command-line-application/
In short, that means I'm using setuptools with the entry_points option in my setup.py file:
import programs
setup(
name='my_package',
entry_points={
'gui_scripts': [
'program1 = programs.program1:main',...
]
})
My package is uploaded to PyPI, and can be installed using pip. Normal behavior on the command line is that program1 launches the GUI.
The problem is, I would like to support the Anaconda distribution of Python. If I pip install and try to run program1 using using Anaconda, I get this warning:
This program needs access to the screen.
Please run with a Framework build of python, and only when you are logged in on the main display of your Mac.
The executable script lives here:
~/anaconda2/bin/program1
And here is its text:
#!/Users/***/anaconda2/bin/python
import re
import sys
from programs.program1 import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
And it is importing program1 from this location:
/Users/***/anaconda2/lib/python2.7/site-packages/programs/program1.pyc
How can I get program_1 to run as an executable using Anaconda?

Cannot Include gi.repository.Gtk in py2exe

I have a project in Python 3.4 and GTK+ 3. I'm on Windows XP SP3 32-bit (VirtualBox).
I need to compile down to an executable using py2exe. (Do NOT suggest cx_freeze. It has ten times the problems on this project than py2exe).
My setup.py is as follows.
#!/usr/bin/python
from setuptools import setup
import py2exe
setup(name="Redstring",
version="2.0",
description="REDundant STRING generator",
author="MousePaw Labs",
url="http://www.mousepawgames.com/",
maintainer_email="info#mousepawgames.com",
data_files=[("", ["redstring.png", "redstring_interface.glade"])],
py_modules=["redstring"],
windows=[{'script':'redstring.py'}],
options={"py2exe":{
"unbuffered": True,
"compressed":True,
"bundle_files": 1,
'packages':['gi.repository'],
}},
zipfile=None
)
When I run it via C:\Documents and Settings\Jason\Desktop\redstring2>python setup.py py2exe, I get the following output (in full).
running py2exe
running build_py
1 missing Modules
------------------
? gi.repository.Gtk imported from __SCRIPT__
Building 'dist\redstring.exe'.
C:\Documents and Settings\Jason\Desktop\redstring2>
The actual script, redstring.py, runs without a hitch in my Windows environment. In that, I have the following (working) line of code: from gi.repository import Gtk That is ALL I import from gi.repository in the entire project.
If I swap the line in setup.py to 'packages':['gi'],, the error output switches to about 24-some-odd missing modules, all of them belonging to gi.repository. If I try and import "Gtk" or "gi.repository.Gtk" in either 'packages': or 'includes':, I get an error that the file in question being imported cannot be found.
I spent eight hours on #python (IRC channel) today, and no one could solve this. I need this packaged down to a Windows binary this week.
NOTE: This question is not a duplicate; while it is a similar issue, it is a) not the same error message, and b) neither answer solves the question in any way.
I solved this by, first of all, downgrading to Python 2.7. (GTK+ 3.8 is still fine.) py2exe apparently has known issues with Python 3.
Second, I switched...
options={"py2exe": {
"bundle_files": 1,
}
to
options={"py2exe": {
"bundle_files": 3,
}
For some reason, py2exe cannot include certain files needed to run the gi library when 'bundle_files' is set to 1 or 2.
The full setup.py that works with py2exe for my project can be found on GitHub. I run it on cmd with python setup.py py2exe.

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

Categories