I just upgraded from Fedora 30 to Fedora 32. All my python stuff stopped working.
The first problem was with
import gtk
I read that I should switch it to
from gi.repository import Gtk as gtk
from gi.repository import Gdk
But many many modules are not present. For example:
AttributeError: 'gi.repository.Gtk' object has no attribute 'combo_box_new_text'
AttributeError: 'gi.repository.Gtk' object has no attribute 'WINDOW_TOPLEVEL'
AttributeError: 'gi.repository.Gtk' object has no attribute 'settings_get_for_screen'
A huge mess.
How do I fix this?
Using Gtk 3:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
in gtk use:
self.window.set_position(gtk.WIN_POS_CENTER_ALWAYS)
in Gtk 3 use:
self.set_position(Gtk.WindowPosition.CENTER)
So must convert your code to version 3 .
Related
Details about my system;
Ubunttu 22.04.2 LTS x86_64
pyqtgraph v0.13.1
pyhton v3.10
The code I'm trying to run on line 56;
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
app = QtGui.QApplication([])
The Error I get;
AttributeError: module 'pyqtgraph.Qt.QtGui' has no attribute 'QApplication'.
is QApplication no longer supported in pyqtgraph?
Not sure on what to do, I got this source code from github and I don't completely understand what the author was doing.
Edit:
I get a similar error on line 58.
win = pg.GraphicsWindow(title="plotting")
AttributeError: module 'pyqtgraph' has no attribute 'GraphicsWindow'.
I'm trying to run a Python program that tries to import
from PyQt4 import QtGui, QtCore
and gives me an Import Error: No module named 'PyQt4'.
I use a conda environment and made sure: pyqt is installed, version 5.6.0.
If I change the import statement to
from pyqt import QtGui, QtCore
It doesn't work either, it gives me the same import error. At this point I'm totally confused:
Why is it telling me there is no module named pyqt? I know it is there. If I type conda list it shows me that it is installed.
Trying to install PyQt4 via pip or conda fails because apparently there is not package named PyQt4, there is only a package named pyqt. How can this program try to import PyQt4 then?
How can I fix this?
I'm on Ubuntu 16.04 and Python 3.
Try using PyQt5 like below:
from PyQt5 import QtGui, QtCore
I cannot make Python3 work with GTK3. I'm in a cluster context and I had everything recompiled from the sources.
When I run a simple example :
from gi.repository import Gtk
win = Gtk.Window()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
I have the following error :
ERROR:root:Could not find any typelib for Gtk
Traceback (most recent call last):
File "gtk3_example.py", line 2, in
from gi.repository import Gtk
ImportError: cannot import name 'Gtk'
There are typically additional packages to install depending on what you want to introspect. The one I found that was crucial was gir1.2-gtk-3.0 (or 2.0 depending which version you are coding against).
The problem is due to the compiled version of GTK3 that was not referenced in gobject-introspection.
It is simple to check the problem by listing the .typelib files in gobject-introspection
$ which g-ir-scanner
/Produits/publics/x86_64.Linux.RH6/gobject-introspection/1.40.0/bin/g-ir-scanner
$ ls /Produits/publics/x86_64.Linux.RH6/gobject-introspection/1.40.0/lib/girepository-1.0/
cairo-1.0.typelib fontconfig-2.0.typelib GIRepository-2.0.typelib GModule-2.0.typelib win32-1.0.typelib xlib-2.0.typelib
DBus-1.0.typelib freetype2-2.0.typelib GL-1.0.typelib GObject-2.0.typelib xfixes-4.0.typelib xrandr-1.3.typelib
DBusGLib-1.0.typelib Gio-2.0.typelib GLib-2.0.typelib libxml2-2.0.typelib xft-2.0.typelib
The problem should be solved by recompiling GTK (and its dependencies) with the configure option --enable-introspection=yes.
Try using the following code:
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import GTK
I'm lost in version 3.. in python2+gdk2 is:
#!/usr/bin/env python2
import gtk
gtk.gdk.window_process_all_updates()
window_xid = 54525964
gdk_window = gtk.gdk.window_foreign_new(window_xid)
which is pretty much straight forward. But then, the horror:
#!/usr/bin/env python3
from gi.repository import xlib
from gi.repository import Gdk
from gi.repository import GdkX11
Gdk.Window.process_all_updates()
xlib_window = "???????"
gdk_display = GdkX11.X11Display.get_default()
gdk_window = GdkX11.X11Window.foreign_new_for_display(gdk_display, xlib_window)
the xlib is killing me.. I'm unable to do anything with it. Has anybody worked with it before??
The documentation I've through several times already is:
Gdk3,
Xlib
Getting the window from its xid was the fastest way to get a screenshot in python2 I guess I'll have try another way in python3.. any ideas? maybe peek_children from root window?? but then, how do I know if it's the window I want?
A Window in X11 is the same as an XID. There's just a typedef from one to the other.
So in C code gdk_x11_window_foreign_new_for_display() just accepts an Window or XID, which is basically an integer. This also works in python using introspection:
#!/usr/bin/env python3
from gi.repository import Gdk
from gi.repository import GdkX11
Gdk.Window.process_all_updates()
xlib_window = 0x2a00005 # from xwininfo command
gdk_display = GdkX11.X11Display.get_default()
gdk_window = GdkX11.X11Window.foreign_new_for_display(gdk_display, xlib_window)
print(gdk_window.get_geometry())
I've successfully installed Qt4.7.3, Python 3.2, SIP, & PyQt4. Or I think I do? I can
import PyQt4
without any issues but when I try to run this:
#!/usr/bin/env python3
import sys
from PyQt4 import QtGui
app = QtGui.QApplication(sys.argv)
widget = QtGui.QWidget()
widget.resize(250, 150)
widget.setWindowTitle('simple')
widget.show()
sys.exit(app.exec_())
I get this error:
Traceback (most recent call last):
File "./simple.py", line 6, in <module>
from PyQt4 import QtGui
ImportError: cannot import name QtGui
I've checked the paths and they seem to be fine but when looking for the components I can't find them? I do have libQt.a and libQtCore.a where I assume those components would be. I just can't seem to access them.
Any ideas?
Thanks.
If you use #!/usr/bin/env python3 you can not be sure which version of python starts up. For testing you should directly use python3.2!
Since import PyQt4 works and from PyQt4 import QtGui not, it is likely that the files in the PyQt4 module directory are misplaced.
The QtGui.so file needs to resist directly in the PyQt4 directory!
On GNU Systems this directory can be found at /usr/lib/python3/dist-packages/PyQt4/ and on Windows at %SystemDrive%23/Python32/Lib/site-packages/PyQt4/.
This might help finding the directory on Mac OS:
import PyQt4
print(PyQt4.__file__)