[GIS] How to import GeoPandas in QGIS 3.10

anacondageopandasimportpythonqgis

Here is the situation: I've installed QGIS 3.10 with the downloadable .exe file and accepting all as predefined. The Python version used with it is 3.7.0 like here:

import sys
sys.version
'3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)]'

The thing now is that I'm working on a script that need GeoPandas and I'm not able to install or import it:

import geopandas
Traceback (most recent call last):
  File "C:\PROGRA~1\QGIS3~1.10\apps\Python37\lib\code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "C:/PROGRA~1/QGIS3~1.10/apps/qgis/./python\qgis\utils.py", line 737, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
ModuleNotFoundError: No module named 'geopandas'

I tried to install anaconda and within it I'm able to install pip and GeoPandas without any issues but it comes with Python 3.7.4. I have no deep understanding about how several Python versions work together within the same PC.

So, my issue here is easy: I need to be able to import GeoPandas in the Python console regarding that I use QGIS 3.10 and it works with Python 3.7.0.

I use Windows 10, by the way.

Best Answer

In order to install the module with the right Python, it is better to use python -m pip install geopandas instead of pip install geopandas. You can follow the following steps:

  1. Find python.exe which is in your QGIS folder. (Example: C:\OSGEO4~1\apps\Python37)
  2. Opens a command prompt
  3. Type the following command: cd C:\OSGEO4~1\apps\Python37 & python -m pip install geopandas

Replace the OSGEO path with your QGIS path.

Related Question