I used to use spyder as python IDE and was learning QGIS developing recently. But I cannot import qgis.core in spyder although the library can be imported in QGIS Desktop Console successfully.

qgis desktop

Here is my setting environment:

My OS is Windows 7;

Spyder was integrated in Anaconda2-4.1.1-Windows-x86_64 and install together, in which default interpreter is Python 2.7.12(64bit)

QGIS 2.18 was installed by Standalone installer 64bit but python is 2.7.5 64bit. Then I modified the environment variables by appending

“C:\Program Files\QGIS 2.18\apps\qgis\python” in PYTHONPATH and

“C:\Program Files\QGIS 2.18\apps\qgis\bin;

C:\Program Files\QGIS 2.18\apps\qgis\python;

C:\Program Files\QGIS 2.18\apps\qgis\python\qgis\core;” in Path.

However, I still cannot import it in Spyder’s IPython, error says”DLL load failed:” spyder import Same error even I change the interpreter to QGIS’s 2.7.5 with Desktop open.

spyder change default

In term of OSGeo4W Shell, that is another problem.

Still failed to import it when finding no module at first opening, but it works only once if run Germán Carrillo’s BAT file. OSGeo4W

Which means that I have to run this batch file every time I start OSGeo4W Shell.

So it is weird my addition path in PATH and PYTHONPATH have no effect at all.


I do not familiar with spyder since I write scripts by PyCharm which is pretty awesome. And I have solved your problem according to the blog. http://spatialgalaxy.net/2014/10/09/a-quick-guide-to-getting-started-with-pyqgis-on-windows/.

Here is my batch script to run PyCharm with QGIS python packaged.

SET OSGEO4W_ROOT=C:\Program Files (x86)\QGIS Brighton
SET GRASSNAME=grass\grass-6.4.4
SET PYCHARM="C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.3\bin\pycharm.bat"

CALL "%OSGEO4W_ROOT%"\bin\o4w_env.bat
call "%GRASS%"\etc\env.bat
path %PATH%;%QGIS%\bin
path %PATH%;%GRASS%\lib

set PYTHONPATH=%OSGEO4W_ROOT%\apps\Python27\Lib\site-packages;%PYTHONPATH%

start "PyCharm aware of QGIS" /B %PYCHARM% %*

I believe you can solve in the same way. enter image description here May you succeed!

  • If you want to hide bat file window (cmd console window) - change variable PYCHARM to "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2.3\bin\pycharm.exe" Oct 4 '17 at 7:17

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.