Using https://spatialgalaxy.net/2018/02/13/quick-guide-to-getting-started-with-pyqgis3-on-windows/ I created a .bat file to load the OSGeo4W and QGIS paths into PyCharm. Now I am getting an error importing geopandas with

import geopandas "OSError: could not find or load spatialindex_c-64.dll"

I can find the dll in my OSGeo4W folder and I can import geopandas in QGIS.

Bat File

    @echo off
    call "%OSGEO4W_ROOT%"\bin\o4w_env.bat
    call "%OSGEO4W_ROOT%"\apps\grass\grass78\etc\env.bat
    @echo off
    path %PATH%;%OSGEO4W_ROOT%\apps\qgis\bin
    path %PATH%;%OSGEO4W_ROOT%\apps\grass\grass78\lib
    path %PATH%;C:\OSGeo4W3\apps\Qt5\bin
    path %PATH%;C:\OSGeo4W3\apps\Python39\Scripts

    set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis\python
    set PYTHONHOME=%OSGEO4W_ROOT%\apps\Python39

    set PATH=C:\Program Files\Git\bin;%PATH%

start "PyCharm aware of QGIS" /B "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2021.1.1\bin\pycharm64.exe"

1 Answer 1


To get geopandas working in a OSGeo Pycharm environment you need to import qgis processing using...

from qgis import processing


import geopandas

will bring in the geopandas package

EDIT 20220513

import qgis

Will also work.

  • That's odd! Did you try to import other modules like PyQt? That's where my IDE fails: from PyQt5.QtCore import QVariant May 13 at 15:00
  • I assume that PyCharm is using the Interpreter from apps/Python39 and not from bin? By the way, I have an open ticket in the osgeo4w trac system on this bug: trac.osgeo.org/osgeo4w/ticket/735 May 13 at 15:21
  • As for my Python dir it is using the OSGeo4W\apps\Python39\python.exe I can switch to OSGeo4W\bin\python.exe and I don't get errors on importing the PyQt5.QtCore stuff geopandas also imports. I'm not an expert, this just worked for me it might cause me issue later on. May 13 at 15:51
  • I stumbled onto from qgis import processing as a solution by playing with some code I copied out of the QGIS model builder. FYI import qgis also works, it appears geopandas and perhaps the PyQt5 is installed within the processing module. Pycharm still shows a red exclamation mark saying it cannot find reference QtCore or QVariant but the script runs with no errors so I am assuming it is importing those components as well. Full disclosure, I'm not an expert I completely stumbled onto this and I yet to have found current directions for getting Pycharm setup with QGIS\OSGeo parameters. May 13 at 15:58
  • I'm using PyScripter and discovered the same error than you. If the code runs in the QGIS-Console, everything is fine, even when using the command line interpreter in the OsGeo4w-Shell. But any "external" IDE fails. I'm just guessing, that the IDE uses the python3.exe from apps/Python39 and that this causes the import error. May 13 at 16:18

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.