I'm trying to run a script using python. The script requires some qgis functionality. I believe I have set the path, pythonpath, etc. correctly. The OS is Windows 7 64-bit with qgis located at the non-standard location Z:\Program Files\QGIS 2.18.

I receive

"Z:\Program Files\QGIS 2.18\bin\python.exe" "Z:/Locating Incident  

Traceback (most recent call last):
File "Z:/Locating Incident Response/Solver/pyspatialopt-master
/pyspatialopt-master/examples/binary_mclp_qgis.py", line 11, in <module>
import qgis
File "Z:\Program Files\QGIS 2.18\apps\qgis\python\qgis\__init__.py", line 
27, in <module>
from qgis.core import QgsFeature, QgsGeometry
File "Z:\Program Files\QGIS 2.18\apps\qgis\python\qgis\core\__init__.py",
line 30, in <module>
from qgis._core import *
ImportError: DLL load failed: The specified module could not be found.

Process finished with exit code 1

What am I doing wrong?

(I should note that the loading of qgis works fine in the Python console. Not surprisingly!)

  • 1
    It seems there's a typo. Use from qgis.core import * instead of from qgis._core import *
    – mgri
    Mar 9, 2017 at 8:01
  • An import of qgis fails... The code above works on my linux box. Mar 9, 2017 at 21:05

1 Answer 1


I think the best way to do this is to use the OSGeo4W shell.

I still need to set a couple of environment variables

set PYTHONPATH=Z:\Program Files\QGIS 2.18\apps\qgis\python
set PATH=Z:\Program Files\QGIS 2.18\apps\qgis\bin;%PATH%

but at least I can import qgis!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.