I am trying to use QGIS in stand-alone python scripts (windows 10, python 3.6.6).

After the following steps...

1) create new conda environment (geospatial)

2) install the qgis conda-forge package through conda install -c conda-forge qgis as per conda-forge page (https://anaconda.org/conda-forge/qgis)

3) run anaconda prompt and activate the geospatial environment

... I run python and try to import qgis.core. However I get the "ModuleNotFoundError" error.

(geospatial) C:\Users\vince>python
Python 3.6.6 | packaged by conda-forge | (default, Jul 26 2018, 11:48:23) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import qgis.core
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'qgis'

From reading other resources, it seems PYTHONPATH and PATH need to be set, but after setting those (see below), I still get an error on import qgis.core, this time an "ImportError: DLL load failed" error.

See the following anaconda prompt output:

(geospatial) C:\Users\vince>set PYTHONPATH=C:\Anaconda3\envs\geospatial\Library\python

(geospatial) C:\Users\vince>set PATH=C:\Anaconda3\envs\geospatial\Library\bin;%PATH%

(geospatial) C:\Users\vince>python
Python 3.6.6 | packaged by conda-forge | (default, Jul 26 2018, 11:48:23) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import qgis.core
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Anaconda3\envs\geospatial\Library\python\qgis\__init__.py", line 72, in <module>
    from qgis.core import QgsFeature, QgsGeometry
  File "C:\Anaconda3\envs\geospatial\Library\python\qgis\core\__init__.py", line 34, in <module>
    from qgis._core import *
ImportError: DLL load failed: The specified module could not be found.

The (Python) paths I set above were "derived" from similar paths I found when one wants to use QGIS API by installing "osgeo4w. So, the main question: When using the Conda-Forge QGIS package, what are the required PYTHONPATHs and PATHs to be set; and/or what other configuration is needed to get the conda-forge QGIS package going?

  • Welcome to GIS SE. As a new user, please take the Tour, which emphasizes the importance of asking One question per Question. Please Edit your Question to ask one question.
    – Vince
    Jan 30 '19 at 1:59
  • 2
    @VincentV Hello. Have you found the answer yet? Your question is where many of us are stuck!
    – Ash
    Sep 29 '19 at 15:46

If those steps are exactly what you did the problem may be that you installed the package in the wrong environment.

Prior to installing qgis (step 2) you have not activated the environment which means qgis is installed in you base environment. You are then trying to add the path to a library outside of the environment which can be tricky for an application like this.

Try activate 'geospatial' first and then install qgis.


Hopefully somebody who understands the internal processes better than me can provide an answer.

You can add GDAL to your Anaconda installation, and use it this way for example:

import gdal
import ogr   # it should also be available if gdal is present

And then use these packages in your standalone script, which reproduces the internal processing of QGIS. For example:

srs = ogr.osr.SpatialReference()  # to define a spatial reference

geom = ogr.CreateGeometryFromWkt(MultiLineString(variable1).to_wkt()) # to work with geometries

I'm not sure if you can call the full QGIS environment in Python without runnning the QGIS app, since many items (for example, different GUI components) may be called and created when the environment starts up. If they cannot be created (because the GUI didn't start up), errors may occur.

Again, one of the developers can confirm this or teach us how to make it work.

Side note: Another very good way to handle spatial data in Python is using geopandas (for vector data) and rasterio (for raster data). They work well together too, without complications. Feel free to try them out.


I think that the problem doesn't come from the PYTHONPATH or the PATH but from the fact that the _core file has the extension .pyd. When you rename it _core.py it finds it but you still get an error because pyd aren't the same thing as py.

For the moment the only way I found to work around this is to use the python library that is inside the qgis installation.


It is the problem of your environment path variable, and you have to specify the correct path to find the DLL library of QGIS. Please try to follow the steps illustrated in this link below to get all environment path variables correctly specified:


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.