py2app with anaconda Python 3 "missing constraints" error - python-3.x

I am trying to compile a bare-bones wxPython project in Python 3 using py2app.
py2app 0.13 <pip>
wxPython 4.0.0a3.dev3059+4a5c5d9 <pip>
Python 3.5.3 :: Anaconda custom (x86_64)
OS X 10.12.4
Here is my setup.py file:
from setuptools import setup
import sys
sys.setrecursionlimit(2000) # need this to prevent max recursion depth reached
APP = ['wx_py2app.py']
DATA_FILES = []
OPTIONS = {'plist': {'PyRuntimeLocations':
['/Users/***/anaconda/lib/libpython3.5m.dylib',
'/Users/***/Python/simple_examples/dist/wx_py2app.app/Contents/Frameworks/libpython3.5m.dylib']}
}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
Here is my wxPython code:
import wx
class simpleapp_wx(wx.Frame):
def __init__(self, parent, wx_id, title):
wx.Frame.__init__(self, parent, wx_id, title, size=(100, 100))
self.Show()
if __name__ == "__main__":
app = wx.App()
frame = simpleapp_wx(None, -1, 'my application')
app.MainLoop()
I had to make a few patches. First, I had to hard code /Users/***/anaconda/lib/libpython3.5m.dylib into py2app/build_app.py, or else it would look for libpython3.5.dylib instead and crash here:
ValueError: '/Users/***/anaconda/lib/libpython3.5.dylib'
Second, I patched PyQt5/uic/port_v2/load_plugin.py to avoid a syntax error, and PyQt5/uic/port_v2/ascii_upper.py which was using deprecated string.maketrans.
My bare-bones project works fine in alias mode, but in non-alias mode the project compiles, but then when I open it it immediately terminates:
Detected missing constraints for <private>. It cannot be placed because there are not enough constraints to fully define the size and origin. Add the missing constraints, or set translatesAutoresizingMaskIntoConstraints=YES and constraints will be generated for you. If this view is laid out manually on macOS 10.12 and later, you may choose to not call [super layout] from your override. Set a breakpoint on DETECTED_MISSING_CONSTRAINTS to debug. This error will only be logged once.
As a side note, my project does work without this problem when I compile it in alias mode. Otherwise, I haven't been able to figure out anything about this error. How can I debug or fix this?

Related

PyQt5 layout.addWidget will not accept pyqtgraph widget [duplicate]

This question already has an answer here:
Adding pyqtgraph to PyQt6
(1 answer)
Closed 4 days ago.
I am trying to add a GraphicsLayoutWidget from pyqtgraph to a PyQt application. On multiple machines, the code below works without error: I see a QLineEdit input textbox above a black square.
import pyqtgraph as pg
from PyQt5.QtWidgets import QWidget, QLineEdit, QVBoxLayout, QLabel, QApplication
import sys
class Test(QWidget):
def __init__(self, headers: list = None, parent=None):
QWidget.__init__(self, parent=parent)
layout = QVBoxLayout(self)
layout.addWidget(QLabel('QLineEdit'))
w = QLineEdit()
print(type(w))
layout.addWidget(w)
x = pg.GraphicsLayoutWidget()
print(type(x))
layout.addWidget(x)
if __name__ == "__main__":
app = QApplication(sys.argv)
main = Test()
main.show()
app.exec()
However, on one machine, I receive the error below and the code will not run.
File "my_file.py", line 22, in __init__
layout.addWidget(self, w)
TypeError: addWidget(self, a0: QWidget, stretch: int = 0, alignment: Union[Qt.Alignment, Qt.AlignmentFlag] = Qt.Alignment()): argument 1 has unexpected type 'GraphicsLayoutWidget'
I've tried adding a self.setLayout(layout), but this doesn't fix the issue.
I updated both machines so that their installed packages and versions both match. On the non-working machine, I tried uninstalling pyqtgraph and PyQt5, then reinstalling them with PyQt5 first followed by pyqtgraph. The error persists.
On both machines I am running:
Python 3.11.1
PyQt5 5.15.8
pyqtgraph 0.13.1
All other packages that I see listed by pip freeze or pip list are identical in version, i.e. the lists contain the same packages and the same versions of each package.
The print lines in the above code print the class of each object.
For QLineEdit: <class 'PyQt5.QtWidgets.QLineEdit'>.
For GraphicsLayoutWidget: <class 'pyqtgraph.widgets.GraphicsLayoutWidget.GraphicsLayoutWidget'>.
I've run the code in PyCharm as well as from the command line and the result is the same. For some reason, it seems that PyQt5 is not identifying widgets from pyqtgraph.widgets as QWidget.
I don't even know how to reproduce the error on the working machines.
I'm not sure where to go from here.
You may have to specify the stretch.
Can you run this example?
Also I've normally used pyqt.PlotWidget for general graphing with no problems.

SDL2 module not found

I'm using python 3.7.9 and I have this code:
import kivy
from kivy.app import App
from kivy.uix.label import Label
class MyApp(App):
def build(self):
return Label(text='Hello world')
if __name__ == '__main__':
MyApp().run()
And I get this error:
Yes, I've tried reinstalling all kivy libraries multiple times, I've tried reinstalling Python but I still get this error.
My project settings:
My configurations:
I've even found it in 'External Libraries' folder:
I've tried to fix for literally 3 hours now and I'm too frustrated so I'm asking you guys. Thank you in advance.
First, forget pycharm, follow the kivy install instructions and see if you can run a kivy app via python from the command line. If you can't, debug this without the pycharm environments getting in the way.
If you can install and run kivy outside of pycharm, then your only problem is that you haven't installed it correctly within whatever python environment pycharm is using. I don't know how you configure it, but you'd need to make sure kivy and its dependencies are installed in that environment.

Can't exit PyQt application on 3.7.4 and Spyder

Running on Windows 10 64 bit and Python 3.7.4 (no Anaconda), the basic script from Terminate PyQt Application
import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QLabel, QGridLayout, QWidget
from PyQt5.QtCore import QSize
class HelloWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setMinimumSize(QSize(640, 480))
self.setWindowTitle("Hello world")
centralWidget = QWidget(self)
self.setCentralWidget(centralWidget)
gridLayout = QGridLayout(self)
centralWidget.setLayout(gridLayout)
title = QLabel("Hello World from PyQt", self)
title.setAlignment(QtCore.Qt.AlignCenter)
gridLayout.addWidget(title, 0, 0)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
mainWin = HelloWindow()
mainWin.show()
sys.exit( app.exec_() )
does not exit when starting from Spyder.
The IPython console simply "idles", but never returns. Running the script from the command prompt (i.e. 'python script.py') works OK.
Switching back to a fresh install of Python 3.7.2, everthing works as expected. The IPython version is in both cases 7.7.0.
In both cases (3.7.2 and 3.7.4) all modules including Spyder had been installed via pip.
Any idea why that is? Is it a Spyder related issue?
Keeping the Graphics Backend as not "Inline" is creating this problem.
Either change the graphics backend as,
Tools -> Preferences --> IPython Console -> Graphics --> Graphics Backend as Inline
Or Restore the default settings of the Spyder Environment. Which can be done by,
Tools -> Preference --> Reset to Defaults.

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

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