py2app tkinter 'Detected missing constraints' error - python-3.x

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?

Related

ImportError: No module named tkinter. Mac OS Terminal

I have created a Tkinter window in a python script. The script runs perfectly in the python IDLE and generates the GUI. However, when I run this file outside of the IDLE by clicking on it on my Desktop, the terminal responds with ImportError: No module named tkinter. Even though tkinter is installed as its a default module when python is installed. Any help is much appreciated. Im working on python 3.7
Make sure your default python , the one that the terminal calls has tkinter installed.
So run 'python --version' in the terminal and if that yields 3.7 then your default python is 3.7.
Now try to import tkinter using that same python version.
open the terminal and run python then run import tkinter as tk
If that does not yield an error saying that the module was not found then most probably you are running the executable with the wrong permissions.

Cannot import Tkinter on visual studio code?

Ok, I am having a weird issue going on. From what I understand Tkinter is supposed to be built in with python 2 and 3.
I can import and use Tkinter just fine in my terminal under python3 as well as with IDLE3. However, when I try to import Tkinter in Visual Studio Code I get an "ImportError: No module named 'tkinter'.
The same issue was happening in Pycharm also but I had my interpreter set to the same as my terminal and not a project-specific interpreter.
I have tried the following:
import tkinter
from tkinter import *
try:
import tkinter
except ImportError:
import Tkinter as tkinter #Even though I'm using python3
None of this is working, Any idea why?
Also I am using Linux Mint.
I've been stuck with the same issue for weeks now where my VSC says there are no tkinter module but in shell and terminal it runs fine.
Solution: I found out that in the left buttom corner there is an interpreter that runs as Python 2 just click and select Python 3
In windows you could have selected to not install the needed tkinter components when python was installed (its optional in the installer).
Try running the installer again, and make sure these components are selected.
If your interpreter is PHP2 it is spelled "Tkinter" in the code. (uppercase)
If your interpreter is PHP3 then you should spell it like "tkinter"
When you were installing python there is a option. Install tkinter and ide just check it and then reinstall python after that close and open vs code. Here you go!

ValueError: character U+6573552f... Py2aap

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

How to determine what version of python3 tkinter is installed on my linux machine?

Hi have been scavenging the web for answers on how to do this but there was no direct answer. Does anyone know how I can find the version number of tkinter?
In Python 3, it's tkinter with a small t, and you need to import it. Thus:
>>> import tkinter
>>> tkinter.TkVersion
8.6
If you didn't import it, you'd get the error you mentioned.
tkinter.TclVersion and tkinter.TkVersion described in other answers provide the major and minor Tcl/Tk versions but not the patch number.
On the other hand, the info patchlevel Tcl command returns the version in the major.minor.patch format.
import tkinter
tcl = tkinter.Tcl()
print(tcl.call("info", "patchlevel"))
# Output:
# 8.6.10
The following should be preferred to call the command from a Tkinter app, which already has an associated Tcl interpreter:
import tkinter
root = tkinter.Tk()
...
print(root.tk.call("info", "patchlevel"))
# Output:
# 8.6.10
Type this command on the Terminal and run it.
python -m tkinter
A small window will appear with the heading tk and two buttons: Click Me! and QUIT. There will be a text that goes like This is Tcl/Tk version ___. The version number will be displayed in the place of the underscores.
You cal so invoke TclVersion:
>>> import tkinter
>>> tkinter.TclVersion
8.6
Tested for Python 3.6.5 and Python 3.5.2 (Ubuntu 16.04.4):
Run Tkinter.TclVersion or Tkinter.TkVersion and if both are not working, try Tkinter.__version__
In the terminal try as follows:
python -m tkinter or python3 -m tkinter

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