import gtk/glib produces ImportError: DLL load failed - python

I installed the latest versions of python (2.6.5), gtk+, pygtk (and friends) from their respective websites on Windows XP SP3. When you try to import gtk (or just glib for that matter), an ImportError is raised:
Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import gtk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python26\lib\site-packages\gtk-2.0\gtk\__init__.py", line 38, in <module>
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 <module>
from glib._glib import *
ImportError: DLL load failed: The specified procedure could not be found.
This was working on the same machine around 6 months ago, although this time around I have re-installed. I tried different versions of the libraries but still couldn't get it to work.
There are a couple of pages out there relating to this, but not suggest a solution, and I'm unable to find one.

I got a work around this by installing the windows GTK+ runtime as indicated in this link
http://www.gramps-project.org/wiki/index.php?title=Windows_installer#Installation
Also see their page dedicated to troubleshooting import errors on windows: http://www.gramps-project.org/wiki/index.php?title=ImportError:_DLL_load_failed

I managed to solve this myself. Firstly, there can be more than one cause so this may not help everyone.
I went through the PATH system environment variable and removed all paths that pointed to old versions of gtk+ (for example, those that come packaged with applications).

Same problem, answer was to reinstall pygtk from grampy page.
It was problem of pygtk, not system or gtk.
(Before this, import pygtk works well)

I had this same exact problem on Windows 7 64. I tried installing multiple versions of python 2.6, and the all-in-one pygtk that is supposed to give you GTK+ also. This installer didn't seem to do anything. Then I installed the latest versions of GTK+ (from binary), pygtk, pycairo, and gobject (all explained on the pygtk downloads website). When I did this, I got the ImportError: DLL load failed: The specified procedure could not be found. that is given above.
The SOLUTION was to uninstall pygtk, pycairo, gobject and remove the GTK+ bin location from my path variable. Then I went here and did the first 5 steps (in that order) under "Dependencies - The Hard Way". And now it works. Note: I didn't install gramps, just the pygtk part (first 5 steps).

Some reports indicate that the trick is to import pygtk first. Have you tried that?

I have copied gtk module (site-packages: gtk-2.0, pygtk.py, cairo) to other python installation and encountered the same problem.
It was happening because I forgot to copy site-packages/pygtk.pth.

Related

Is dbm.gnu not supported on Python 3.7 Windows?

When doing
import dbm.gnu
on a standard Python 3.7.6 (64) for Windows, I get:
File "C:\Python37\lib\dbm\gnu.py", line 3, in
from _gdbm import *
ModuleNotFoundError: No module named '_gdbm'
Isn't dbm.gnu supported out of the box on Windows?
The same problem happens with:
import dbm.ndbm
File "C:\Python37\lib\dbm\ndbm.py", line 3, in
from _dbm import *
ModuleNotFoundError: No module named '_dbm'
I tested on another Python 3.6.8, and it's the same.
This has always been the case (that gdbm and ndbm are not supported on windows). See also issue 3769 for background and dbm and windows, and issue 3783 for something to work on if you want to contribute to making the dbm story on windows better.
Googling found a gdbm port to windows, so if you are trying to use source files from linux, that might help you. We're open to suggestions on improving the situation here, but someone has to figure out what would make sense and champion it. Bundling the gdbm windows port is probably not an option, but making it possible to install something via PIP that will work is, if there's anything in core preventing that currently.

How to reuse modules across Python installs?

I am trying to import a python (2.7.5) module but I'm not sure if I am going at it in the right way. I usually work in Jupyter Notebook (in a seperate Conda env) to keeps things organized per project. Now I am trying to import a module called otbApplication which are Python bindings for a GIS program called Orfeo Toolbox. The thing is, Orfeo Toolbox (together with QGIS) comes with its own Python install (and subsequent paths) and even its own CMD prompt (assuming you use OSGEO4W). If I use this CMD prompt to start Python and import otbApplication, it works fine. But I want to install more packages and just work within my own 'usual' environment (Jupyter Notebook) in this case.
How should you normally reuse modules between Python installations?
I already tried placing a .pth txt file containing the path to the module in one of the sys.path locations of a different Python installation but it wouldn't even find it. I tried to force it by hosting a notebook (with the same Python install) in the same folder as the module and then importing it. I got the following error which makes me question if I am going at this the wrong way:
Python 2.7.5 |Continuum Analytics, Inc.| (default, Jul 1 2013, 12:37:52)
[MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import otbApplication
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "otbApplication.py", line 28, in <module>
_otbApplication = swig_import_helper()
File "otbApplication.py", line 24, in swig_import_helper
_mod = imp.load_module('_otbApplication', fp, pathname, description)
ImportError: DLL load failed: The specified module could not be found.
This means that forcing the same paths to my new installation is not enough, what am I missing? Apologies for the long story (or the probable butchering of some of the terms).
Kind regards,
Jasper
You've got the right idea with the .pth file, but in order to get it to work you need to check some prerequisites. Obviously, the syntax needs to be good (just give the directory locations separated by line breaks). A common issue is that folks don't put the .pth files in the correct directory (usually though not necessarily \Lib\site-packages). I bet that if you check these you'll be okay.
**Also: as noted in the comments be aware that 32-bit python isn't going to like a 64-bit DLL and verse-visa, so ensure that you're running the right version of python when you try to access those libs.

exe generated from a python script with Py2exe does not work on xp

I have a python script that works fine on my computer (Python 2.7 32 bit installed). It has the following imports :
import mechanize
from bs4 import BeautifulSoup
from Tkinter import *
import json
import webbrowser
I wanted to distribute this to others so I found that we can create exe files using py2exe. I wrote a script like this:
from distutils.core import setup
import py2exe
setup(console=['notification.py'],
options = {'py2exe' : {
'packages' : ['bs4', 'mechanize','Tkinter', 'json', 'webbrowser']
}})
This works fine on my computer but when I run it on Windows XP, I get this error -
Traceback (most recent call last):
File "notification.py", line 3, in
File "Tkinter.pyc", line 38, in
File "FixTk.pyc", line 65, in
File "_tkinter.pyc", line 12, in
File "_tkinter.pyc", line 10, in __load
ImportError: DLL load failed: %1 is not a valid Win32 application.
I tried searching other threads but found none that has the same problem. So please help me fix this issue.
Maybe Tinkiter is a 64 bit version GUI, while Windows XP version you run it is 32bit.
Check it out and tell us if that's the case.
Reason I assume this is the line:
ImportError: DLL load failed: %1 is not a valid Win32 application.
combined with the fact that Tinkiter is 64 bit.
Python can be 32 bit. Works on both Operating Systems, 32 and 64 bit ones.
But Tinkiter is a GUI, something different than the language.
So Including a 64bit add-on, into a 32bit application... can cause some trouble. :)
Suggestion:
You can start by making the app work in console interface if possible.
Then you can use another GUI that can run in 32 bit.
For instance, you can get a 32bit version of THIS
Edit: Added a suggeston.
Well, I had installed both versions of Python 32 bit and 64 bit in my machine. When I was making it a stand alone probably some dlls were copied from the wrong library. So I completely uninstalled both versions and then installed 32 bit and it worked fine.

ImportError: DLL load failed: not a valid Win32 application

I am trying to use Cython to wrap a C++ class. Basically I follow the example at this page.
I'm using Windows7 64-bit, Python 2.7.4 64-bit, MinGW 4.3.3 (32/64bit), and the SDK has been set to x64 mode.
In this case, I successfully build the .pyd file. I tried to import it with following code:
import sys
sys.path.append("C:\\Rectangle")
import rect
The first two lines work well. When I input the third line, it gave following message:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import rect
ImportError: DLL load failed: %1 is not a valid Win32 application.
I compiled the extension in 64bit mode, and every piece of software I used is at least compatible with 64bit. How could such error happened?
May I know how can I work around this?
Many thanks! :-)
I ended up switching everything to 32bit (python, wxPython, etc.), and everything is fine now.
So, I would really recommend that you use "file rect.pyd" command to determine if your module is really 64bit.

maya2008 win32api 64 bit python

How is it possible to run import win32api successfully on a 64bit maya version 2008?
The following error occurs:
Error: No module named win32api
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named win32api
I need to get mouse cursor position in python so that I can place window exactly in that position. Is there any other way to get it?
Best regards,
kNish
Maya uses its own Python installation. You need to add the path where pywin32 is installed by one way or another ... you can create a .pth file in
C:\Program
Files\Autodesk\Maya2009\Python\Lib\site-packages\
Also, like Adam pointed out, make sure you have the 64 bit pywin32 installed.
Here's an article talking about this subject:
http://www.rtrowbridge.com/blog/2008/11/27/maya-python-import-scripts/
Edit:
Yeah indeed I think they don't provide PyWin32 for Python25 x64:
Available for AMD64 versions of
Windows for Python 2.6 and later
(support for Python 2.5 is just too
hard, sorry). Lots of help from
Roger, Steve Yin and Sidnei da
Silva.
http://sourceforge.net/project/shownotes.php?release_id=603349

Categories