Error loading pygtk import gtk

I downloaded everything described in pygtk for installation. Everything went fine until I tried to enter "import gtk" , it selected ImportError as follows:

 from gtk import _gtk ImportError: DLL load failed: ...(something unreadable) 

Then I install pygtk-2.22.0 again, the same problem exists. So what to do, please? Thanks in advance!

+4
source share
5 answers

The error you describe is usually caused by the python binding (pygtk / pygobject / pycairo), which cannot load the DLL in which it should function properly. Most of these errors are caused by:

  • GTK + runtime is not part of the PATH environment variable. This has long been advice on how to get pygtk to work on Windows. Please do not change your user or the PATH system variable, it is no longer needed for the multifunction installer.
  • several versions of GTK + runtime are in your PATH environment variable and in the first (leftmost), one is not compatible with the versions of pygtk / pygobject / pycairo used. That's why adding GTK + to a PATH environment variable is a bad idea: it's easy to mix versions (sometimes GTK +-related installers add their garbage to the PATH directory during installation, which contains older or incomplete runtimes).
  • a rare case when some software package installed libintl.dll and iconv.dll in% WINDIR% \ system or% WINDIR% \ sytem32

The easiest way to avoid the dll addon described above is to use the PyGTK All-in-One Installer (http://download.gnome.org/binaries/win32/pygtk/2.22/). It contains both Python and GTK + and even Glade bindings and makes it no longer necessary to change the PATH environment variable.

A small warning: if you decide to use the all-in-one installer, you will have to remove the individual pygtk / pygobject / pycairo packages that you used before (or you will be in a world of trouble ...)

+2
source

read the source code, maybe there is a need for a specific version of pygtk

edit the source code to work with the pygtk version

0
source

I also had this problem. You probably didn’t mention it in your answer, so I suggest the obvious (well ... the obvious for people who have been using it for a while, maybe). Did you use the following three lines of code to import? You must use them to import PyGTK.

I assume your version here is 2.24, like mine. If not, change it to the version you have.

 import pygtk pygtk.require('2.24') import gtk 

This is enough to import gtk.

0
source

Problem

As others have noted, don't put gtk in the path. I know it is tempting and it works on XYZ, but it (to put it mildly) is confusing. The addiction agent is bad on a Linux platform that is trying to make your job easier.

To find out what PyGTK All In One does for you, install (which is apparently complete) gtk + runtime directly into your python package folder, for example, in C: \ Python \ Lib \ site-packages \ gtk-2.0 \ runtime

Decision

NOTE :% YOURPYTHONPATH% is an EXAMPLE variable that contains the path to your Python installation (for example, C: \ Python, or C: \ Python27, or whatever it is). I suggest setting% PYTHON_DIR% or% PYTHON_PATH% if you want to use a variable to do this, since more programs can use this.

For your XYZ program to require GTK to work, add % YOURPYTHONPATH% \ Lib \ site-packages \ gtk-2.0 \ runtime \ bin to PATH when you start your program; the correct versions of the DLL that it should reference are in this folder. All the other GTK + that I installed (GTK + / GTK2-Runetime) gave me errors.

Again; Do not try to set a user or system level variable (do not open the dialog box below), as this will probably cause problems for you later if you are NOT VERY sure that you know what you are doing. If you read this, you most likely don’t know as much as you think you are doing. Instead, change the path on the cmd command line or use the batch / script file to configure it for you.

enter Windows Environment Variables Dialog

0
source

After installing the pygtk.org package, install each of them in the following order:

  • pycairo-1.8.6.win32-py2.6.exe
  • pygobject-2.20.0.win32-py2.6.exe
  • PyGTK-2.16.0 + glade.win32-py2.6.exe
  • GTK + -bundle_2.16.6-20100912_win32.zip

For more information:

http://freetstar.com/windows7-pygtk-gtk/

I got secusses from the link on my pc.

-1
source

All Articles