I have a perfectly fine working script that runs within the QGIS Python Console and I would like to run the script outside of the software, preferably in cmd as a .bat, so then I can use task scheduler to run the task every minute. I am using QGIS downloaded with OSGEO4W64. My .bat looks like this and runs, until it encounters a variable within QGIS e.g. QGSRasterLayer
or QgsPrintLayout
:
ECHO OFF
cd C:\Path\to\.py Script
C:\OSGeo4W64\apps\Python37\python.exe .\Full_Script.py
PAUSE
NameError: name 'QgsRasterLayer' is not defined
I know I have to do from qgis.core import QgsRasterLayer
but every time I try to use this piece of code, it says that 'qgis' is not defined
. I have looked into many forums on this site and have looked mainly into path and PYTHONPATH
environment variables. My path looks like this:
C:\OSGeo4W\apps\Python37
C:\OSGeo4W\apps\Python37\lib
C:\OSGeo4W\apps\Python37\Scripts
C:\OSGeo4W\bin\qgis-bin.exe
And my PYTHONPATH
looks like this:
c:\OSGeo4W64\bin\python
I have also tried using sys.path.append
but I have had no luck so far. Can anyone help me out so I can sort out this problem and finally get my script working outside of QGIS, as I am struggling to find a way how to resolve this issue? Have I inputted the paths wrong or do I need to do something else, in order so that I can import qgis.core
and be able to use all the elements (QgsRasterLayer
etc) in my script, outside of QGIS.
EDIT: I currently have it working now but it comes up with the error: NoneType object has no attribute 'RasterLayer'