Bug report #16042

In standalone python script `from qgis._core import *` produces ImportError: DLL load failed: The specified module could not be found

Added by Raphael Dumas over 7 years ago. Updated over 7 years ago.

Category:Python plugins
Affected QGIS version:2.14.9 Regression?:No
Operating System:Windows 7 Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:Yes Copied to github as #:23957


In Windows 7 x64 SP1 using Python 2.7 x64, I installed QGIS 2.14.9 from the standalone x64 installer. I was trying to set up a python virtual environment to develop standalone app (http://gis.stackexchange.com/a/223325/36886). I added the following paths to a .pth file in the environment's site-packages:

C:\\Program Files\\QGIS Essen\\apps\\qgis-ltr\\python
C:\\Program Files\\QGIS Essen\\apps\\Python27\\
C:\\Program Files\\QGIS Essen\\apps\\Python27\\Lib\\
C:\\Program Files\\QGIS Essen\\apps\\Python27\\Lib\\site-packages
C:\\Program Files\\QGIS Essen\\bin
C:\\Program Files\\QGIS Essen\\include
C:\\Program Files\\QGIS Essen\\apps\\qgis-ltr\\bin

But when I type from qgis.core import *, python tries to import qgis._core and fails with

ImportError: DLL load failed: The specified module could not be found

Having a look at the qgis/_core.pyd file with DependencyWalker produces the attached output image

dp_walker_qgis.PNG (27.3 KB) Raphael Dumas, 2017-01-05 08:16 AM


#1 Updated by Raphael Dumas over 7 years ago

Sorry, fired off this issue a little prematurely.

I resolved the import error by adding the following to my PATH variable.

C:\\Program Files\\QGIS Essen\\apps\\qgis-ltr\\bin
C:\\Program Files\\QGIS Essen\\bin

Though I would highlight that just adding C:\\Program Files\\QGIS Essen, as the documentation suggested, didn't work. http://docs.qgis.org/2.14/en/docs/pyqgis_developer_cookbook/intro.html#running-custom-applications

#2 Updated by Matthias Kuhn over 7 years ago

  • Status changed from Open to Closed

Thanks for posting this followup.

Would you mind improving the description in the cookbook?

It should be trivial to create a improvement proposal (pull request) using the online editor here:

Thank you in advance!

Also available in: Atom PDF