Pyside6/Qt6 crash in MacOS - macos

The following program opens a window with a button that displays which version of PySide is in use. If you click the button, the program displays Wikipedia's home page.
It works fine on PySide 6.3.
On PySide 6.4, it works fine, UNLESS you maximise the window before pushing the button. If you do that, it segfaults.
I'm running Python 3.9 on MacOS Monterey.
import PySide6 as qt
import PySide6.QtWidgets as qtw
import PySide6.QtWebEngineWidgets as qtweb
app = qtw.QApplication([])
def showWeb():
stack.setCurrentWidget(web)
web.setUrl("https://en.wikipedia.org")
button = qtw.QPushButton(qt.__version__)
button.clicked.connect(showWeb)
web = qtweb.QWebEngineView()
stack = qtw.QStackedWidget()
stack.layout().addWidget(qtw.QWidget())
stack.layout().addWidget(web)
window = qtw.QWidget()
window.setLayout(qtw.QVBoxLayout())
window.layout().addWidget(button)
window.layout().addWidget(stack)
window.resize(400, 400)
window.show()
app.exec()
The error message on the zsh terminal looks like this:
zsh: segmentation fault python3 segfault.py
[... my command prompt ...] % [67231:259:1105/160207.214403:ERROR:mach_port_rendezvous.cc(310)] bootstrap_look_up org.chromium.Chromium.MachPortRendezvousServer.1: Permission denied (1100)
[67231:259:1105/160207.214737:ERROR:child_thread_impl.cc(226)] Mach rendezvous failed, terminating process (parent died?)

Related

matplotlib works and is installed, but there is still an error No module named 'matplotlib'

I installed matplotlib and it works and runs when I run commands.
import matplotlib.pyplot as plt
plt.plot([1,2,3,4], [1,4,9,16], 'ro')
plt.axis([0, 6, 0, 20])
plt.show()
But for some reason, I still get the error that matplotlib is not installed, and plus when I run plt, it doesn't show the available library functions
No library functionsAn error that no module , but the chart still runs
I clicked to install matplotlib, the error message disappeared, but the available library functions did not appear either. And plus after a while the error would come backThe error comes back after about 30 seconds
I've tried installing in different ways.
Installing via Pycharm Python Packages
Installation via Pycharm terminal

Problem with destroy in tkinter under Anaconda Spyder

In the following program, I can close the window with its close button but neither with the 'Esc' binding, nor the button callback. I am sent to the IPython console but the window stays here with a spinning wheel ! Works fine in the Terminal or with Anaconda IDLE. I am on Mac, High Sierra, Anaconda and Spyder last versions (IPython 7.1.1, Spyder 3.3.2). I suspect a problem with Spyder.
from tkinter import *
class Myapp(object):
def __init__(self):
self.root = Tk()
self.root.geometry('150x100+1+1')
self.root.title('Root')
self.root.bind('<Escape>', lambda e: self.root.destroy())
self.button = Button(self.root, text='End Program', command=self.end)
self.button.place(x=10, y=45)
self.L = [1,2,3] # result of an omitted computation
def end(self):
self.root.destroy()
app = Myapp()
app.root.mainloop()
print(app.L)
Any hint ? Thanks.
(Spyder maintainer here) You have two options to make your code work in Spyder:
Go to
Tools > Preferences > IPython console > Graphics
and deactivate the option called Activate support. Then after running your code, it'll block the console, but you won't have any other problems with it.
If you selected Tk as the backend in
Tools > Preferences > IPython console > Graphics
then you need to remove app.root.mainloop() from your code because using our Preferences creates a Tk event loop so your code doesn't block the console, and that makes app.root.mainloop() unnecessary.
Destroy doesn't work in spyder for me either, but does work fine from the system's Terminal. Carlos Cordoba's advice doesn't help.
I'm on a Mac OS Mojave, with most recent versions of Anaconda Python and Spyder available for Mojave.
I would post this as a comment, but don't have the reputation to do that.

Python.exe keeps running after closing Gtk.main() when both Gtk and win32ui modules are imported

I run python 2.7.13 on windows 7.
I am creating a window with Gtk (from pygobject 3.18.2).I also use win32ui (from pywin32 221).When I import both modules my program runs just fine untill I close it. The window is closing fine, but the python process keeps running and the cmd window that is used to run the script does not return to de cmd prompt.I have to kill python to get back to the promptHere is a simple test script. This does not close proper on my system. If I comment out
#import win32ui
it will close proper
from gi.repository import Gtk
import win32ui
class Window(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.connect("destroy", Gtk.main_quit)
self.show_all()
Window()
Gtk.main()
Looks like a conflict between Gtk and win32ui.I need win32gui and win32ui for extracting icons from pe files.What can I do?
On previous versions of PyWin32:
https://sourceforge.net/p/pywin32/bugs/609/
https://sourceforge.net/p/pywin32/bugs/636/
import atexit, os
def taskkill_this():
# kill this process
current_pid = os.getpid()
os.system("taskkill /pid %s /f" % current_pid)
atexit.register(taskkill_this)
Appears to be one provided workaround.
Upon further inspection, it appears to be related to pywin32 and Gtk UI event processes clashing. I would recommend using one or the other rather than both if possible or use a taskkill hack like the one above.
I've also noticed that this has happened on Windows 7 workstations in all cases I have seen.

Can't make a tk image Button with IPython Notebook

I'm using an IPython notebook to create a Tk application in Python. I can make a button with a text label:
%matplotlib tk
import tkinter as tk
root = tk.Tk()
button = tk.Button(root, text = 'IPython')
button.pack()
But if I try to make a button with an image I get an error message. This code works fine when run from the command line, but crashes when executed in an IPython Notebook:
%matplotlib tk
import tkinter as tk
root = tk.Tk()
img = tk.PhotoImage(file='IPy_header.gif')
print(img)
button = tk.Button(root, image = img)
button.pack()
The print statement verifies the PhotoImage object was created (i.e. no 'file not found' errors). The call to tk.Button leads to this error:
TclError: image "pyimage2" doesn't exist
I'm using ipython/jupyter 3.0.0 on Mac OS X 10.10.3
Anybody have a suggestion?
You may have to enable the tk event loop with %gui tk
magic-gui documentation.

interactive mode doesn't switch on from script (matplotlib 1.4.0 python 2.7.5 on mac osx 10.8.5)

Using python 2.6 on my mac the following works fine (i.e. a plot window opens):
import matplotlib.pyplot as plt
from numpy import linspace, sin, pi
plt.ion()
print "Is interactive:?", plt.isinteractive()
x = linspace(-pi, pi, 1001)
plt.plot(x, sin(x))
raw_input() #keep the window open
It works when I run it in shell (i.e. $ python test.py) as well as when I run it in an interactive python terminal.
I recently installed python 2.7 and with it nothing happens (more precisely, plot window appears in Dock, but doesn't open) when I run my script from shell. The value of plt.isinteractive() is false even after plt.ion().
When I run the same code in an interactive python terminal, everything is fine.
The answer to this question makes the plot window appear, but I find it annoying that now I have to add plt.pause(0.1) to my script.
Is there a way to get the earlier behaviour without modifying the code?
The backend is macosx.
It seems that this is a bug related to matplotlib 1.4. An ugly workaround is to include:
import sys
sys.ps1 = 'SOMETHING'
before importing matplotlib.
Alternatively, one can use ipython to run the script.
For more details see here https://github.com/matplotlib/matplotlib/issues/3505

Resources