Intro: QGIS
A open source software on GeoTIFF (.tff), which has many tools for viewing and processing. It embedded a Python Console, but has little information on python script.
Here is a simple way to use qgis lib in python file as in python console.
1. Take a look in QGIS python console
First, I think PATH
is the key. I output the path in console.
import sys
sys.path
It will output the path like below:
['D:/Program Files/QGIS 3.16/apps/qgis-ltr/./python', 'C:/Users/$USR/AppData/Roaming/QGIS/QGIS3\\profiles\\default/python', 'C:/Users/$USR/AppData/Roaming/QGIS/QGIS3\\profiles\\default/python/plugins', 'D:/Program Files/QGIS 3.16/apps/qgis-ltr/./python/plugins', 'D:\\Program Files\\QGIS 3.16\\apps\\Python37', 'D:\\Program Files\\QGIS 3.16\\apps\\Python37\\Scripts', 'D:\\Program Files\\QGIS 3.16\\bin\\python37.zip', 'D:\\Program Files\\QGIS 3.16\\apps\\Python37\\DLLs', 'D:\\Program Files\\QGIS 3.16\\apps\\Python37\\lib', 'D:\\Program Files\\QGIS 3.16\\bin', 'C:\\Users\\$USR\\AppData\\Roaming\\Python\\Python37\\site-packages', 'D:\\Program Files\\QGIS 3.16\\apps\\Python37\\lib\\site-packages', 'D:\\Program Files\\QGIS 3.16\\apps\\Python37\\lib\\site-packages\\win32', 'D:\\Program Files\\QGIS 3.16\\apps\\Python37\\lib\\site-packages\\win32\\lib', 'D:\\Program Files\\QGIS 3.16\\apps\\Python37\\lib\\site-packages\\Pythonwin', 'C:/Users/$USR/AppData/Roaming/QGIS/QGIS3\\profiles\\default/python']
We can see a variable with site-packages
, so there should be the python interpreter location, like “D:\Program Files\QGIS 3.16\apps\Python37\python.exe”
And export all path to pickle, which will be used in coding space
import pickle
f=open("QGIS_ALL_PATH")
pickle.dump(sys.path,f)
f.close()
2. Work with VS code
https://docs.qgis.org/2.8/en/docs/index.html https://docs.qgis.org/3.16/en/docs/user_manual/processing_algs/