Sunday, 26 August 2018

pyqgis - Installing 3rd party python libraries for QGIS on Windows


How can I use 3rd party libraries on QGIS plugins on Windows?


I've developed a plugin that uses rasterio and numpy for a customer, but he's having problems installing rasterio and numpy.


Actually rasterio and numpy were installed in it's main system Python (C:\Python27), but I need QGIS Python to recognize it.



Answer



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.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...