ImportError: DLL load failed
On Windows GRAMPS is usually started from the menu entry or a short cut to the same location, that is fine when everything is working. When your system is experiencing the problem described here, trying to start GRAMPS will cause the GRAMPS GUI to never appear, and you will get no user information back about the problem.
The only visibility to the actual problem will be when you start GRAMPS from the command prompt, in that case you will get the error message from python similar to the following:
C:\Program Files\gramps>"c:\Python26\python.exe" gramps.py 483: ERROR: gramps.py: line 138: Unhandled exception Traceback (most recent call last): File "gramps.py", line 188, in <module> errors = run() File "gramps.py", line 179, in run from gui.grampsgui import startgtkloop File "C:\Program Files\gramps\gui\grampsgui.py", line 53, in <module> import gtk File "c:\Python26\lib\site-packages\gtk-2.0\gtk\__init__.py", line 48, in <module> from gtk import _gtk ImportError: DLL load failed: The specified procedure could not be found.
What is happening is that python is trying to load the Gtk runtime, when python is unsuccessful loading the runtime, it will throw an exception and dump the above trace out. There can be many reasons why python cannot load the gtk-runtime.
Now it is up to the user to diagnose what is wrong with his/her system and rectify it. Unfortunately since there have been multiple causes for the error in the past this can be quite difficult resulting in potential GRAMPS users to throw their hands up in disgust and give up, this page is solely to discuss possible methods to identify and fix the above problem.
In the above example, python was called passing in the script for GRAMPS, this is a complicated test case, so I'd like to try and simplify it to a minimal test case that exhibits the same behaviour. This minimal test case can then be used when testing if changes to the environment have had any effect on the problem. The minimal test case does not even use GRAMPS.
Minimal test case
Simply start a python command line.
How to start Python 2.6 command line on Windows XP using the Start Menu
Once the command prompt has started type import gtk in the command prompt window.
Python 2.6.3 (r263rc1:75186, Oct 2 2009, 20:40:30) [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 48, in <module> from gtk import _gtk ImportError: DLL load failed: The specified procedure could not be found. >>>
If your minimal test throws the exception as shown you have just proved the problem exists between python and gtk-runtime, this is not a GRAMPS problem. How you proceed from here is dependent on your own skill set and how dirty you are willing to get your hands.
Whenever you try to fix your systems environment to rectify the problem, your will need to close the python command line and start a new one, so it can pick up the new environment from the system
check_gtk_install was an attempt to create a script to help diagnose problems with the gtk install, it has been of limited success, sometimes helping, sometimes confusing more. Possibly the biggest problem, is that the output of the script can be cryptic and can need someone with prior knowledge to decode it.
You will need to download check_gtk_install.py the check script benefits from a couple of other third party components to be downloaded as well. The script does not need the 3rd party components, but the scripts usefulness will be limited without them.
- Win32Api Provides some ability to handle dos short path names that might be encountered in the path environment variable. This is a python library, download and install as you would any python library.
- Dependency Walker Most importantly this program analyses executables/DLL's dependencies it is excellent for identifying missing DLL's. This is a zip file, download and expand the contents of the zip into the same directory that you saved the script check_gtk_install.py
Run the script from the windows command prompt and check the output of the script. Should you become stuck, cannot make head or tail of the output, then consider posting a description of your problem and the output of check_gtk_install on the GRAMPS Users forum.
When viewing the results of the output, you should pay particular attention to any line that starts with ERROR: these lines will give specific clues to what the problem may be.
The section of output dedicated to DependencyWalker section may post a number of issues, that may safely be ignored depending on your operating system. for example:
==== Checking with Dependency Walker ==== Please be patient takes some time Testing file c:\python27\Lib/site-packages/gtk-2.0/gtk/_gtk.pyd EFSADU.DLL Error dll not found IESHIMS.DLL Error dll not found WER.DLL Error dll not found ERROR: c:\windows\system\INTL.DLL Version 0.12.0.0 ERROR: c:\windows\system\ICONV.DLL Version 126.96.36.199 MS runtime Version 9.0.21022.8 loaded from c:\windows\system32\MSVCR90.DLL MS runtime Version 9.0.30729.4148 loaded from c:\windows\winsxs\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4148_x-ww_d495ac4e\MSVCR90.DLL
This snippit of output shows 3 DLL's whose line ends with Error dll not found, after getting such a result, a little research online showed they are only are relevant for other versions of Windows and can safely be dismissed as a cause of the problem.
The two lines starting with ERROR: are of more interest. These two DLL's should have been loaded from the gtk-runtime directory, however for whatever reason they have been found and loaded from c:\windows\system . In this case removing/renaming those two DLL's in the windows directory allowed python to correctly import gtk, hence GRAMPS was then able to work.
What had happened in the above case, although the two DLL's were found in windows\system, the gtk-runtime could not work with them as they were from an older installation, and not the correct version for the current gtk installation.
In another installation, MSVCR90.DLL was only in a winsxs sub-directory and not in c:\windows\system32\. PyGTK seems to only be able to use MSVCR90.DLL if it is in the c:\windows\system32\ directory. Copying the latest version from a winsxs sub-directory to the c:\windows\system32\ directory fixed the DLL load failure. (Note: In the example the WINDOWS directory is on the C: drive; If, as the result of a dual-boot install, C: is not the active Windows partition, C: needs to be replaced with the drive designator of the active WIndows drive)
In another example (below) you can see that some DLL's were found in other installation directories, this may or may not affect the ability of python to import gtk, it depends if the dll's in the other directories are compatible with what the gtk-runtime needs or not. In one case I had a perfectly working system, but it was picking up DLL's from other installations, in this case upgrading another program can suddenly break the gtk installation.
==== Checking with Dependency Walker ==== Please be patient takes some time Testing file C:\Python26\Lib/site-packages/gtk-2.0/gtk/_gtk.pyd DWMAPI.DLL Error dll not found ERROR: c:\program files\graphviz2.26\bin\LIBGDK-WIN32-2.0-0.DLL Version 188.8.131.52 ERROR: c:\program files\miktex 2.8\miktex\bin\MSVCR90.DLL Version 9.0.30729.1
Output from check_gtk_install.py should be used as a guide to possible issues, it is possible for the script to give the thumbs up, but a problem still exists on the system.
I want to discuss how to use dependency walker on it's own to achieve the same aim.