ValueError: character U+6573552f... Py2aap - python-3.x

I made a very simple program and I'm trying to export it to an app file. I'm currently using Python 3.6 and py2app to convert the py file into app.
So I created the setup file:
from setuptools import setup
OPTIONS = {'iconfile':'sc.icns',}
setup(
app = ['hello.py'],
options = {
'py2app': OPTIONS},
setup_requires = ['py2app']
)
and then in the terminal I enter:
python3 hello_setup.py py2app
After some seconds it creates the dist folder and in it there is the hello.app, the problem is when I run it, it appears a window that says "hello error" then I open the .exec file inside the application to see the terminal and it shows this error:
ValueError: character U+6573552f is not in range [U+0000; U+10ffff]
Why does it appear? How do I fix it? Thank you very much.
In case that it is needed, here is the code of 'hello.py'
from tkinter import *
from tkinter import messagebox
root = Tk()
def printworld():
messagebox.showinfo('Hello', 'Hello World')
button1 = Button(root, text='Press me!', command=printworld)
button1.pack()
root.mainloop()

This is an issue with the latest version of py2app==0.14.
You should open a issue with them to get it fixed in current version. In the meantime you can go back one version and it will work fine
pip install py2app==0.13

Related

PyInstaller executable doesn't show GUI

I'm currently working on a program that accepts a specific file as input, works on the data and provides two graphs through Matplotlib (the only module imported in the data parsing file).
For this I have made a small GUI for the user to choose the file to have a graph made of. (w/ tkinter and PIL imported).
I have to make an app out of this and I'm using PyInstaller to it. Unfortunately I haven't been able to make the final file work (or run properly).
I have already made several modifications either to the code itself, but also to the PyInstaller's .spec file.
I have added the function to fix the path for PyInstaller.
I have modified the .spec file to add the path to an image, not to show the console.
I have tried with these settings both on/off: UPX, One File.
I have checked the log files for missing modules as everything seems to be ok.
Some of the code:
Imports on the GUI file:
import sys
import os
import tkinter as tk
from tkinter.filedialog import askopenfilename
from tkinter.messagebox import showerror
from PIL import ImageTk, Image
import rectifierDataParser
Imports on the Data Parsing file:
import sys
import os
import matplotlib
matplotlib.use("TkAgg")
from matplotlib import pyplot as plt
GUI File:
class Application(tk.Frame):
def __init__(self, master = None):
tk.Frame.__init__(self, master)
self.pack()
self.createWidgets()
def createWidgets(self):
self.fileButton = tk.Button(self, text(...))
self.quitButton = tk.Button(self, text(...))
self.fileButton.pack(side = 'top')
self.quitButton.pack(side = 'bottom')
def load_file(self):
filename = askopenfilename(title = "Select file", filetypes = [("Files", ("*.001", (...)))]
rectifierDataParser.main(filename)
def resource_path(relative_path):
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
app = Application()
app.master.title('Graphing Data')
app.master.geometry('300x200')
img = ImageTk.PhotoImage(Image.open("logo.jpg"))
panel = tk.Label(app, image = img)
panel.pack(side = "bottom", fill = "both", expand = "yes")
app.mainloop()
As I'm currently not able to see the GUI on the screen, is there any problem with the code itself or any compatibility with PyInstaller (supposedly PyInstaller is fully functional w/Tkinter).
I hope one of you might help me have a breakthrough as I have been stuck on this for way to much time! Many thanks in advance!
There is a few issues with the tcl version that comes with python, discussed here. I've written an script that automatically changes the init.tcl file to the correct version.
N.B. you shouldn't use the --onefile flag as the file directories aren't present, and the script won't work.
cd /path/of/your/app
git clone https://github.com/jacob-brown/TCLChanger.git
pyinstaller --windowed app.py
python TCLChanger/TCLChanger.py
You should now be able to open your app, from the terminal and via double clicking.
I was having exactly the same problem and I fixed it by editing the .spec file.
I had to set
console=True
You'll find this option in the bottom of your .spec file.
Something like this:
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='YOU/EXECUTABLE/NAME',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True)
If you do not find your .spec file you can generate one by running
pyi-makespec yourprogram.py

Py2app app not launching just asks if I want to terminate the app or open console

So I am working on a little project of mine that I want to distribute easily so naturally, I use py2app to make a single .app file that will execute on any Mac computer. I tried this tutorial: https://www.metachris.com/2015/11/create-standalone-mac-os-x-applications-with-python-and-py2app/. The problem is that even if I try the example that he gives in the tutorial it crashes and shows this window:
Crash image if I look in the console log of the event I see these tow errors.
error 17:12:44.313837 +0100 Sandwich Unable to load Info.plist exceptions (eGPUOverrides)
error 17:12:44.472464 +0100 tccd Failed to copy signing info for 3112, responsible for file:///Users/-myname-/folder/projects/SandwichApp/dist/Sandwich.app/Contents/MacOS/Sandwich: #-67062: Error Domain=NSOSStatusErrorDomain Code=-67062 "(null)"
In case this is not enough info here is the code from the tutorial that I used:
import tkinter as tk
root = tk.Tk()
root.title("Sandwich")
tk.Button(root, text="Make me a Sandwich").pack()
tk.mainloop()
this is the setup.py:
from setuptools import setup
APP = ['Sandwich.py']
DATA_FILES = []
OPTIONS = {}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
I have tried to add this to my setup.py in the OPTIONS because I saw other people had it, but the same thing keeps happening:
'argv_emulation': True
Any idea on what is going on?
Thanks in advance :)
I have been facing a problem with the exact same error code (-67062) and managed to resolve it at least for my machine running Python 3.6.8 on macOS 10.14.2.
Open the file ../Sandwich/Contents/MacOS/Sandwich and see the traceback message in Terminal. If tkinter imports are causing your issue like in my case, downgrade py2app via
pip uninstall py2app
and use an older version, e.g.
pip install py2app==0.12
and run py2app again. If you further encounter import problems of unwanted packages, e.g. pillow, you can exclude them with a workaround found here
from setuptools import setup
APP = ['Sandwich.py']
DATA_FILES = []
OPTIONS = {
"excludes": ['pillow', 'Image'] # exclude unwanted dependencies
}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
Ronald Oussoren discussed debugging ImportErrors in py2app which can be found below for further reading:
https://bitbucket.org/ronaldoussoren/py2app/issues/223/errors-on-compiling-in-py2app-i-have-all

.show() and/or.exec() from Pyqt5 not working in Spyder

I have Python 3.6.3 and Spyder 3.2.4, both installed along with Pyqt5 yesterday on a computer with a new installation of Windows 10. I am having a problem running some previously written Pyqt5 code in Spyder. The below code shows a minimum code snippet that reproduces the problem.
The Spyder IPython console hangs indefinitely on running the code, and never opens the window. Ctrl-C does not stop execution, so I have to kill Spyder. If I try to run it line by line, I observe that "w.show()" executes but does nothing, while "app.exec()" is the line that hangs. In contrast, if I instead run it from the command line console, "w.show()" makes a nonfunctional window appear, while "app.exec()" makes the window functional. All of the non-pyqt code I have run in Spyder executes just fine.
I'd prefer to develop code in Spyder because running code from the command line often takes 30-60s to start (presumably from the imports.)
I could run the code in Spyder on my old (now broken) system, so clearly it is a problem with my installation or computer. But I am at a loss as to what. I have already tried disabling my virus software, updating all of the relevant packages with pip, resetting Spyder from the Anaconda prompt, and restarting the computer. Any other ideas?
import sys
from PyQt5.QtWidgets import QApplication, QWidget
if not QApplication.instance():
app = QApplication(sys.argv)
else:
app = QApplication.instance()
print("app started")
w = QWidget()
w.resize(250, 250)
w.move(200, 200)
w.setWindowTitle('Test window')
print('app setting')
w.show()
print("shown")
app.exec_()
#sys.exit(app.exec_())
print("exit")
When running this in python it needs to be modified as below. I've modified your script a little to be able to let it run for you some of the main PyQt conventions. See also my inline comments to make sense of what you're trying to accomplish with your print lines. Enjoy!
# -*- coding: utf-8 -*-
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QWidget
class MyMainUI(QtWidgets.QMainWindow):
def __init__(self, parent=None):
print ' Start Main'
super(MyMainUI, self).__init__(parent)
self.setWindowTitle('Test window')
self.resize(250, 250)
self.move(200, 200)
MySpidercodeHook()
def MySpiderCodeHook(self):
...link/run code...
if __name__ == '__main__':
app = QApplication(sys.argv) # no QApplication.instance() > returns -1 or error.
# Your setting up something that cannot yet be peeked
# into at this stage.
print("app started")
w = MyMainUI() # address your main GUI application
# not solely a widgetname..that is confusing...
x = 200
y = 200
# w.move(x, y) # normally this setting is done within the mainUI.
# See also PyQT conventions.
print 'app setting: moving window to position : %s' % ([x, y])
w.show()
print("shown")
app.exec_()
#sys.exit(app.exec_()) # if active then print "exit" is not shown..
# now is while using app.exec_()
#sys.exit(-1) # will returns you '-1' value as handle. Can be any integer.
print("exit")
sys.stdout.flush() # line used to print "printing text" when you're in an IDE
# like Komodo EDIT.

py2app tkinter 'Detected missing constraints' error

I am trying to package an existing python script that uses tk to choose a file and ask for a value into an app that includes all the dependencies.
I am using MacOS 10.12.5, homebrew python 3.6.1 and py2app 0.14.
The following works fine as a script, but when converted to an app (or -A alias app) I get an error Detected missing constraints for <private>... on the console. Simplified version that still produces the same error:
#!/usr/bin/env python3
# encoding: utf-8
import tkinter as tk
from tkinter import simpledialog
root = tk.Tk()
root.withdraw()
the_answer = simpledialog.askstring("Input", "What is the answer?",)
Am I missing something or is this a bug? If it is a bug is it a tk or py2app bug?

Python 3 tkinter Photoimage "pyimage1" doesn't exist

PhotoImage: Tkinter PhotoImage objects and their idiosyncracies
http://tkinter.unpythonic.net/wiki/PhotoImage
I tested the example with python 2.7.9, 3.2.5, 3.3.5, 3.4.3 in 32bit and 64bit.
(Win 8.1 64bit)
The code works. ( even without pillow )
( in python 3.4.3 64bit I had first an error message.
I've completely uninstalled 3.4.3 and then reinstalled.
Now, the example works also with 3.4.3 64 bit )
# basic code from >>
# http://tkinter.unpythonic.net/wiki/PhotoImage
# extra code -------------------------------------------------------------------------
from __future__ import print_function
try:
import tkinter as tk
except:
import Tkinter as tk
import sys
import platform
print ()
print ('python ', sys.version)
print ('tkinter ', tk.TkVersion)
print ()
print (platform.platform(),' ',platform.machine())
print ()
# basic code -------------------------------------------------------------------------
root = tk.Tk()
def create_button_with_scoped_image():
# "w6.gif" >>
# http://www.inf-schule.de/content/software/gui/entwicklung_tkinter/bilder/w6.gif
img = tk.PhotoImage(file="w6.gif") # reference PhotoImage in local variable
button = tk.Button(root, image=img)
# button.img = img # store a reference to the image as an attribute of the widget
button.image = img # store a reference to the image as an attribute of the widget
button.grid()
create_button_with_scoped_image()
tk.mainloop()
This is done by replacing the root.Tk() by root.Toplevel()
Your script works fine for me with exactly the same version of Python 3.4 running on windows 7. I suspect the only difference is that I have also installed Pillow by downloading the wheel package from this repository. I think this includes the image support you need.
As a side note: on windows use the ttk package widgets to get buttons that actually look correct for the platform. Just import tkinter.ttk as ttk then use ttk.Button instead of tk.Button.
Update
Given the same code is working on my machine and not yours I thought I would add how I obtained this version. I installed python using chocolatey (choco install python) then added Pillow, lxml, numpy, requests and simplejson from the gohlke site.
Checking the Tk version I see that I get Tk 8.6.1 so I suspect you are picking up a Tcl/Tk installation installed locally and not shipped with your version of Python. Try ensuring no Tk installation is in your PATH and see if that resolves the problem. My output was:
python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)]
tkinter 8.6
Test Tk location:
>>> from tkinter import *
>>> root = Tk()
>>> root.eval('set tk_library')
'C:\\opt\\Python34\\tcl\\tk8.6'
I actually persuaded python to install to c:\opt\Python I think by using choco install python -ia "TARGETDIR=c:\opt\Python" but I doubt that is relevant.
You must close all open windows, which hang in the memory. If you have an error and did not destroy the window the next time you start not started there several windows. Check!

Resources