I want to use PyQGIS function crs.isValid()
in normal Python file outside of QGIS like this:
wkt = 'GEOGCS["WGS84", DATUM["WGS84", SPHEROID["WGS84", 6378137.0, 298.257223563]],' \
'PRIMEM["Greenwich", 0.0], UNIT["degree",0.017453292519943295],' \
'AXIS["Longitude",EAST], AXIS["Latitude",NORTH]]'
crs = QgsCoordinateReferenceSystem(wkt)
assert crs.isValid()
In the documentation it says that:
If you’re outside the PyQGIS console, the code snippets on this page need the following imports:
from qgis.core import (QgsCoordinateReferenceSystem,
QgsCoordinateTransform,
QgsProject,
QgsPointXY
)
But it doesn't mention how to install qgis.core
to my Python. If I do something like pip install qgis
I get this error message:
ERROR: Could not find a version that satisfies the requirement qgis (from versions: none) ERROR: No matching distribution found for qgis
Is there a way to use PyQGIS functions in a standalone Python file?
pip install qgis
doesn't install pyqgis functions to the python. They are installed by QGIS installers (standalone installer or OSGeo network installer) in Windows. They are also not installed to Python's subfolders, but seperate QGIS subfolders. So you need to make a path to them. And the links in @Taras comment also explains how to do that.