3

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.

  • 2
    Have you tried installing QGIS in a conda environment? Here is a great tutorial on the subject: gisunchained.wordpress.com/2019/05/29/using-qgis-from-conda – Aaron Jan 8 at 18:33
  • I'm aware of it, thanks. The goal is to create a python script that works in several machines and with users that doesn't have any knowledge about python. I hope there is a simple solution on this just to import and execute geopandas tools from the python console in QGIS 3.10 – César Arquero Jan 9 at 7:17
2

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.

| improve this answer | |
  • Thanks. Now I get the following error when installing geopandas: "Collection fiona [...] ERROR: Command errored out with exit status 1: [...] Complete output (1 lines): A GDAL API version must be specified. Provide a path to gdal-config using a GDAL_CONFIG environment variable or use a GDAL_VERSION environment variable. – César Arquero Jan 9 at 8:18
  • The installation of the geopandas module requires numerous dependencies on other modules and frequently returns numerous error messages. A similar question was asked in the following post: stackoverflow.com/questions/54734667/… – Vincent Bré Jan 9 at 8:25
  • I though this would be much easier, like a pair of code lines or something... When I try that fiona manual instalation a new problem comes to light: error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": visualstudio.microsoft.com/downloads. This just never ends... – César Arquero Jan 9 at 9:28
2

Try the following procedure. This worked for me with QGIS 3.10.1 and Windows 10. The only difference is that I have an OSGeo4W install, so hopefully it will work for you with a standalone install.

Firstly, go to https://www.lfd.uci.edu/~gohlke/pythonlibs/#fiona and download the file:

Fiona‑1.8.13‑cp37‑cp37m‑win_amd64.whl

Next create a batch file with the following contents (this should work for your standalone installation):

@echo off
rem Root OSGEO4W home dir to the same directory this script exists in
SET OSGEO4W_ROOT=C:\PROGRA~1\QGIS3~1.10
call "%OSGEO4W_ROOT%"\bin\python-qgis.bat"

rem List available o4w programs
rem but only if osgeo4w called without parameters
@echo on
@if [%1]==[] (echo run o-help for a list of available commands & cmd.exe /k) else (cmd /c "%*")

For an OSGeo4W64 installation, the batch file looks like this:

@echo off
rem Root OSGEO4W home dir to the same directory this script exists in
SET OSGEO4W_ROOT=C:\OSGeo4W64
call "%OSGEO4W_ROOT%"\bin\python-qgis.bat"

rem List available o4w programs
rem but only if osgeo4w called without parameters
@echo on
@if [%1]==[] (echo run o-help for a list of available commands & cmd.exe /k) else (cmd /c "%*")

Just make sure that OSGEO4W_ROOT is set to the directory which contains your installation folders (apps, bin etc). Save this with a .bat extension- preferably in the same OSGEO4W_ROOT directory.

Now, when you double click this batch file it should open you up to a Python prompt in a command window. Type quit() and hit enter. This should return you to a command prompt with the qgis python environment correctly set.

The following steps are more or less based on Underdark (Anita Graser)'s instructions here.

Type pip install geopandas and hit enter. The installation will error at Fiona.

Now type 'pip install C:\Full\Path\To\Fiona‑1.8.13‑cp37‑cp37m‑win_amd64.whl' and hit enter. Note - you need to type the full path to the location where you saved the wheel (.whl) file including the file name. This should successfully install Fiona.

Now type pip install geopandas again and hit enter. If all goes well, this will successfully install geopandas.

Now you can just type exit() and hit enter to exit the command window. Job done!

| improve this answer | |

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.