1

I have python scripts that I use to do some geo-processing. I need to share it with QGIS users that are not familiar with python. I've written QGIS tools in the past using the python interface from QGIS, but the scripts I want to use now contain some modules (e.g., pandas) that I was unable to install on QGIS.

Is there a way to convert my python scripts "as is" to run in QGIS as a tool for non-python users? I can also convert my script to .exe if it makes it easier.

Edited: My inputs are vector file as geojson and my rasters are geo-tifs. I was able to install some modules in QGIS in the past but could not install others. I'm looking for a straight-forward solution (if it exists). Meaning, I have a python (standalone) script that works great on IDE and also works great as exe file (from the cmd), I want to take this script "as is" and convert it so that it would work on QGIS. Is there an easy and simple way to do that?

  • 2
    you can create a plugin: qgistutorials.com/en/docs/building_a_python_plugin.html – RutgerH Apr 9 '18 at 8:00
  • What are the inputs and outputs of your python scripts? I'm guessing they take shapefiles or GeoTIFFs as arguments? You would have to export QGIS layers as those, run your standalone script, and then import the results. Give some examples. – Spacedman Apr 9 '18 at 8:14
  • To install other modules you have to install pip via the osgeo shell, and then the modules... Otherwise you could add a .egg file with the module inside the plugin. – Oscar Campo Apr 9 '18 at 15:25
  • If you need external packages in your Python scripts to use in QGIS tool, then you have two options - tell user to install this modules himself or download source code of the library and include it within the script (remember about the license). This way those libraries will be accessible from the script (and only from the script). – adamczi Apr 9 '18 at 19:00
1

Let me see if I understand: The point is that “QGIS, but the scripts I want to use now contain some modules (e.g., pandas) that I was unable to install on QGIS.” If you are running on windows, don’t use the Qgis.exe to start. You will always find a bat file to start QGis and setup the environment. Depending if you use QGis 2.18 or 3.0.1.

For 2.18 Look for the “qgis-ltr.bat” or “qgis.bat” in

“C:\Program Files\QGIS 2.18\bin”

If you edit the bat. You can add the

set PYTHONPATH = where pandas is ;%PYTHONPATH%

or

set PATH= where pandas is;%PATH%

Then use the .bat to start QGis not the exe

tell us if it works

  • it does not work. I'm using QGIS 2.18 on win10, I did as you suggested, added set PATH= where pandas is;%PATH% to the “qgis.bat” file and started QGIS from that file. When I try to import pandas from the python console in QGIS I get an error No module named pandas. I don't get this error for numpy for example. Anyway, I'm not sure if this is the right solution in my case since I need to share the tool I wrote with other people that use different computers and are not familiar with python or bat files. – user88484 Apr 11 '18 at 5:58
  • Did you add set PYTHONPATH = where pandas is ;%PYTHONPATH% – Alfredo Garcia Apr 11 '18 at 21:15
  • I'm not sure if I understand what you mean. Do you mean if I changed the "where pandas is" to the path where the pandas module is located on my computer? Anyway, I looked up in my system variables where my python is and the name of the variable was PATH. So I added it to the bat file. I do not have PYTHONPATH as a system variable. – user88484 Apr 12 '18 at 13:18

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.