Installing 3rd party python libraries for QGIS on Windows

QGIS, as distributed by OSGeo4W, usually comes with its own Python installation and its own packages that are independent of your "regular" Python installation.

The easiest way to install a Python package into the OSGeo4W distribution is to open the OSGeo4W Shell and use pip from there. This will install the package into the Python distribution QGIS uses, in my case located at C:\OSGeo4W64\apps\Python27\ and the modules accordingly at C:\OSGeo4W64\apps\Python27\Lib\site-packages. You can also do a regular pip list inside the OSGeo4W Shell and your regular Windows Shell (cmd.exe) and compare the outputs to see what packages you might be missing.

If you don't want to install packages to two Python installations you could also try to change the PythonPath to include packages from one installation into the other.

edit: This answer is directed at the original question regarding pip to install modules to be used with QGIS in Windows. OP has since edited/refined the question so this answer is a bit broad now.


Numpy is installed by default in QGIS (Standalone version, OSGeo4W version). For rasterio, there are many problems. I know that rasterio is powerful and easy to use (I use it) but why rasterio in a QGIS plugin while you have all the functions of PyQGIS ? (it was designed for the Python shell or for scripts, not to be used with QGIS/PyQGIS, as Fiona for the shapefiles)

In Linux or Mac OS X (Unix systems), QGIS uses the standard Python installation (independent of QGIS) and if is easy to install or upgrade a Python module (there are also many compilers installed by default)

In Windows, Python is not installed by default, and QGIS installs his own version. To install pure Python modules (without C, C++ libraries) you have solutions (QGIS Standalone and the Python Modules, Installing Python setuptools into OSGeo4W Python or Installing PySAL for OSGeo4W)

But for modules that needs to be compiled (no compiler by default), it is not easy. You can try to copy/paste your installed module in the QGIS Python site_folder but there are problems.

Rasterio need to be compiled against an installed GDAL library and if you install it from Christoph Gohlke Unofficial Windows Binaries for Python Extension Packages, for example, I am not sure that the version of GDAL used by QGIS is the same (for the references to the dll libraries)

If you use exclusively numpy and rasterio, why not an independent script ?


The simple way I found to install libraries for Python in QGIS is

  1. Open OSGeo4W Shell as an administrator

  2. Type py3_env in the console (This should print paths of your QGIS Python installation)

  3. Type python -m pip install {your library}

and its done.