1

I've already asked this question in the "gis.stackexchange" forum, but it seems to be more appropriate for this one.

I am having problems with Python Shell importing the module "qgis.core". When I type "import qgis.core" the Shell ("idle.pyw") gives me this error:

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import qgis.core
ImportError: DLL load failed: Impossibile trovare il modulo specificato (Trad "Impossible to find the specified module").

I have already set the environment to point the right folders following "PyQGIS cookbook" instructions. In my case, the paths are:

PYTHOPATH=C:\"QGIS_path"\apps\qgis\python; Path=C:\"QGIS_path"\apps\qgis\bin.

Am I missing something? What are supposed to be the right libraries the Shell is unable to find? I am working with windows 7 64 bit, QGIS Lisboa (version 1.8), Python 2.7.2 (the one that is included in the QGIS package).

umbe1987
  • 2,894
  • 6
  • 35
  • 63
  • Probably you will find [this](http://stackoverflow.com/questions/12765800/django-error-for-psycopg2-importerror-dll-load-failed) useful, it sounds similar. – gerod May 14 '14 at 14:32

3 Answers3

0

I do not like to mix my python installations, so I add the paths on the fly.
The paths you need are below:

import sys
sys.path.extend([r"C:\Program Files\QGIS Valmiera\apps",r"C:\Program Files\QGIS Valmiera\apps\qgis\bin",r"C:\Program Files\QGIS Valmiera\apps\Python27"])

import qgis.core
PCamargo
  • 584
  • 6
  • 26
  • This hack works for some resources, but not all. If you want to use all QGIS resources, use its own Python installation from your IDE (or from within QGIS itself) – PCamargo Sep 26 '17 at 02:10
0

Check this link import-qgis-core-in-pycharm-no-module-named-pyqt5-qtcore also ignore the pycharm setup if you want.

It works for me,

setup-qgispy.bat

@ECHO off set OSGEO4W_ROOT=C:\QGIS call "%OSGEO4W_ROOT%\bin\o4w_env.bat" call "%OSGEO4W_ROOT%\bin\qt5_env.bat" call "%OSGEO4W_ROOT%\bin\py3_env.bat" path %OSGEO4W_ROOT%\apps\qgis\bin;%PATH% set QGIS_PREFIX_PATH=%OSGEO4W_ROOT%\apps\qgis set GDAL_FILENAME_IS_UTF8=YES set VSI_CACHE=TRUE set VSI_CACHE_SIZE=1000000 set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins set PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis\python set PYTHONHOME=%OSGEO4W_ROOT%\apps\Python37 set PYTHONPATH=%OSGEO4W_ROOT%\apps\Python37\lib\site-packages;%PYTHONPATH% set QT_QPA_PLATFORM_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\Qt5\plugins\platforms set QGIS_PREFIX_PATH=%OSGEO4W_ROOT%\apps\qgis

and then,

C:\> setup-qgispy.bat

C:\> python file.py

Watash1
  • 320
  • 4
  • 7
-2

I think instead of sys.path.extend(). Copy the sys.path from qgis python console and use it. Hope this will work.

Arghya
  • 11
  • 2