I have a QGIS install and a Miniconda install. I want to use the qgis module installed by QGIS in my other python installation, but I get this error:

>>> import qgis
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\QGIS 2.18\apps\qgis\python\qgis\__init__.py", line 26, in <module>
from qgis.PyQt import QtCore
  File "C:\Program Files\QGIS 2.18\apps\qgis\python\qgis\PyQt\QtCore.py", line 30, in <module>
    from PyQt4.QtCore import *
ImportError: DLL load failed: The specified module could not be found.

I have a Python 2.7.5 (same version as QGIS) environment set up, and I am using a bat file in the activate.d directory to set PYTHONPATH and PATH variables on environment activation as per this doc: https://conda.io/docs/using/envs.html#windows

I'm setting PYTHONPATH based on the results of sys.path when run through the python console within QGIS, and doing set PATH=C:\Program Files\QGIS 2.18\apps\qgis\bin;%PATH% which is the path to the qgis_core.dll.

This is the python path:

>>> for i in sys.path:
...     print i

C:\Program Files\QGIS 2.18\apps\qgis\python\plugins\processing
C:\Program Files\QGIS 2.18\apps\qgis\python
C:\Program Files\QGIS 2.18\apps\qgis\python\plugins
C:\Program Files\QGIS 2.18\apps\Python27\lib\site-packages\matplotlib-1.3.1-py2.7-win-amd64.egg
C:\Program Files\QGIS 2.18\apps\Python27\lib\site-packages\nose-1.3.3-py2.7.egg
C:\Program Files\QGIS 2.18\apps\Python27\lib\site-packages\tornado-4.0.1-py2.7-win-amd64.egg
C:\Program Files\QGIS 2.18\apps\Python27\lib\site-packages\backports.ssl_match_hostname-
C:\Program Files\QGIS 2.18\apps\Python27\lib\site-packages\certifi-14.05.14-py2.7.egg
C:\Program Files\QGIS 2.18\bin\python27.zip
C:\Program Files\QGIS 2.18\apps\Python27\DLLs
C:\Program Files\QGIS 2.18\apps\Python27\lib
C:\Program Files\QGIS 2.18\apps\Python27\lib\plat-win
C:\Program Files\QGIS 2.18\apps\Python27\lib\lib-tk
C:\Program Files\QGIS 2.18\bin
C:\Program Files\QGIS 2.18\apps\Python27
C:\Program Files\QGIS 2.18\apps\Python27\lib\site-packages
C:\Program Files\QGIS 2.18\apps\Python27\lib\site-packages\PIL
C:\Program Files\QGIS 2.18\apps\Python27\lib\site-packages\jinja2-2.7.2-py2.7.egg
C:\Program Files\QGIS 2.18\apps\Python27\lib\site-packages\markupsafe-0.23-py2.7-win-amd64.egg
C:\Program Files\QGIS 2.18\apps\Python27\lib\site-packages\win32
C:\Program Files\QGIS 2.18\apps\Python27\lib\site-packages\win32\lib
C:\Program Files\QGIS 2.18\apps\Python27\lib\site-packages\Pythonwin
C:\Program Files\QGIS 2.18\apps\Python27\lib\site-packages\Shapely-1.2.18-py2.7-win-amd64.egg
C:\Program Files\QGIS 2.18\apps\Python27\lib\site-packages\wx-2.8-msw-unicode
C:\Program Files\QGIS 2.18\apps\Python27\lib\site-packages\xlrd-0.9.2-py2.7.egg
C:\Program Files\QGIS 2.18\apps\Python27\lib\site-packages\xlwt-0.7.5-py2.7.egg

My PyQt4 directory only has a directory called uic in it and no other files. Is my install somehow incomplete and is that what is causing this problem?

  • I have the same problem. Did you solve it? – Bulva Jul 18 '17 at 11:15
  • Still haven't solved this. Instead of qgis, I used the fiona, shapely and ogr modules for the project I was working on. – roms Jul 24 '17 at 12:41
  • Ok, thx for reply :-) I made it work on my Ubuntu, but not on Windows at my work. – Bulva Jul 24 '17 at 15:55

Your Answer

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

Browse other questions tagged or ask your own question.