Unable to import gtk after installing PyGObject - python

I can import gtk without any problem previously. I made a GUI in glade for GTK+ 3. Then I thought that I would like to try GTK+ 3. So I installed PyGObject. I later found out that PyGObject has little documentation and I'm using Windows (makes things worse I know).
The problem is here, I can't use import gtk anymore. Neither can I use from gi.repository import Gtk. I've tried installing PyGTK bundle again but it doesn't help.
>>> import gtk
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import gtk
File "C:\Python27\lib\site-packages\gtk-2.0\gtk\__init__.py", line 30, in <module>
import gobject as _gobject
File "C:\Python27\lib\site-packages\gtk-2.0\gobject\__init__.py", line 26, in <module>
from glib import spawn_async, idle_add, timeout_add, timeout_add_seconds, \
File "C:\Python27\lib\site-packages\gtk-2.0\glib\__init__.py", line 22, in <module>
from glib._glib import *
ImportError: DLL load failed: The specified procedure could not be found.`

This looks like C-level library is missing, or at least in a place where the Python wrappers can't find it. Try re-installing whichever version of the C library corresponds to which Python library you would like to use (GTK2 and GTK3 should, theoretically, be parallel installable, but that installing the newer PyGobject broke import gtk suggests that at least these particular bindings aren't for some reason).

Related

Error message received when trying to import turtle (python 3.9, m1 Mac)

When I try to import the python 3 graphical library, turtle, on my m1 MacBook, I get an error message:
david#Davids-MacBook-Air Python Coding Files % /opt/homebrew/bin/python3 "/Users/david/Desktop/Python Coding Files/hello.py"
Traceback (most recent call last):
File "/Users/david/Desktop/Python Coding Files/hello.py", line 1, in <module>
import turtle
File "/opt/homebrew/Cellar/python#3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/turtle.py", line 107, in <module>
import tkinter as TK
File "/opt/homebrew/Cellar/python#3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 37, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
I see it has the library tkinter written in it for some reason. This is weird because on my other Mac, an intel based Mac, with the same python 3 version, and no library such as tkinter install, I didnt get an error message when trying to import turtle
Does anybody know what the problem is?
Python 3's turtle module has always used tkinter. Your other Mac must have tkinter installed. It used to be shipped with Python, but now you need to install it. Assuming you use HomeBrew:
brew install python-tk

PyGObject on Windows "ERROR:root:Could not find any typelib for Gtk"

I need help setting up PyGObject under Windows. I've installed it but I get the following error when importing Gtk and Gdk from gi.repository
ERROR:root:Could not find any typelib for Gtk
Traceback (most recent call last):
File "example.py", line 2, in <module>
from gi.repository import Gtk
ImportError: cannot import name Gtk
I'm able to import gi.repository.GLib, gi.repository.Gio, gi.repository.GObject, gi.repository.cairo and cairo but I can't import gi.repository.Gtk and gi.repository.Gdk and gi.repository.GdkPixbuf.
I have tried uninstalling it from the uninstaller in add/remove programs and then reinstalling it but the error persisted.
If someone could help that would be really appreciated.
I dont know if this is the right answer but check if you have
Gtk-version_number.typelib file in you installation. I had similar problem but I had this problem when I built my program with pyinstaller. I just copied .typelib files and my program worked. I dont know if this applies here but try finding that file and copying to installation sub directory where other .typelib files are.

Packaging with pyinstaller: PyQt4 module not found

Hi everyone and thanks for reading. I'm packaging my python code in a single file using pyinstaller, but when I run my packaged file I get the following error:
Traceback (most recent call last):
File "<string>", line 21, in <module>
File "C:\Users\****\Desktop\pyinstaller-2.0\pyinstaller-2.0\PyInstaller\loader\iu.py", line 409, in importHook
ImportError: No module named PyQt4.QtCore
I don't know what this error is telling me, especially since there is no dir name pyinstaller-2.0 on my desktop and I did not use PyQt4 at all.
Imported modules: Tkinter, tkFileDialog, tkMessageBox, multiprocessing, os, sys, time, numpy, scipy.weave, pywt, matplotlib.pyplot
I think the problem is related to multiprocessing, since I did not experience this error before. I used this recipe to implement the multiprocessing module correctly.
If you were using PyQt then the only way to import the modules with PyInstaller is to use
from PyQt4 import QtCore, QtGui
rather than
import PyQt4.QtCore, PyQt4.QtGui
which your error implies. However, you say that you're not using PyQt.
PyQt is an optional dependency of matplotlib so there is a chance that PyInstaller is checking the matplotlib module and consequently including PyQt.
I would suggest excluding the PyQt module from the build; in your .spec file, search out the line for the Analysis class - something like
Analysis( ..., excludes=['PyQt4', 'PyQt4.QtCore', 'PyQt4.QtGui'])
and edit the excludes keyword arg as suggested above.

Can't import EasyDialogs - ImportError: No module named _Dlg

I'm trying to use the EasyDialogs python module to produce some simple dialog boxes for my python script on OSX. Whenever I try and import the EasyDialogs module I get the following error:
>>> import EasyDialogs
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/EPD64.framework/Versions/6.2/lib/python2.6/plat-mac/EasyDialogs.py", line 24, in <module>
from Carbon.Dlg import GetNewDialog, SetDialogItemText, GetDialogItemText, ModalDialog
File "/Library/Frameworks/EPD64.framework/Versions/6.2/lib/python2.6/plat-mac/Carbon/Dlg.py", line 1, in <module>
from _Dlg import *
ImportError: No module named _Dlg
I've tried doing easy_install Carbon, as I thought it may be due to some issue with the Carbon package for python, but that hasn't helped. Any ideas?
From the paths in your traceback, you appear to be using a 64-bit Enthought Python Distribution. The EasyDialogs module uses various OS X Carbon interfaces, many of which OS X only provides 32-bit versions and have been deprecated by Apple. For this reason, the Python Carbon wrapper and EasyDialogs modules are deprecated in Python 2 and have been removed in Python 3. While they may work in 32-bit mode, you should avoid using them in new code. There are other alternatives available: Tkinter in the standard library, various cross platform GUI frameworks (see here). For more simple dialogs, you could also use the osax package in appscript to use the User Interaction suite of AppleScript's Standard Additions.

Windows XP GTK App Glib Import Error

I am trying to run my GTK app on Windows XP and I am having troubles with an import. I have installed the following as needed and recommended:
python-2.6.msi
gtk2-runtime.2-16.6.exe
pycairo-1.8.6.exe
pygobject-2.20.0
pygtk-2.16.0.exe
pyserial-2.5.exe
However, I am getting the following error when running my script:
Traceback (most recent call last):
File "C:\python26\app\src\start.py", line 22, in <module>
import gtk
File "C:\Python26\Lib\site-packages\gtk-2.0\gtk\__init__.py", line 30, in <mod
ule>
import gobject as _gobject
File "C:\Python26\Lib\site-packages\gtk-2.0\gobject\__init__.py", line 26, in
<module>
from glib import spawn_async, idle_add, timeout_add, timeout_add_seconds, \
File "C:\Python26\Lib\site-packages\gtk-2.0\glib\__init__.py", line 22, in <mo
dule>
from glib._glib import *
ImportError: DLL load failed: The specified module could not be found.
GTK is installed into C:\gtk\bin and is setup in my System PATH.
Am I missing something obvious here?
Any help would be appreciated.
Thank-you kindly.
Andy
I was getting the same issue - I'm not sure why, but I suspect it has something to do with some of the install/lookup paths. I tried adding all sorts of stuff to my path, but nothing seemed to work.
What I did to fix it was to uninstall python et. al. and reinstall using the Python (x,y) package. It's a fairly large download, but it has tons of tools, including several (matplotlib, numpy, scipy, IPython, etc) that I needed/wanted.
You could install pygtk bundle found in this page:
http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/2.22/
where you should find the "all in one" installer suited to your version.
It solved the problem to me without having to install Py(x,y), which seems to be a very usefull scientific environment for windows (I use linux and install all these packages from script).

Categories

Resources