I have tried adding sys.path.append and under cmd.exe set Python Path but am still getting the dreaded ImportError: No module named qgis.core.
I set PythonPath to C:\OSGeo4W64\apps\qgis\python
I have referenced sys.path.append material on this forum and on the QGIS site and I am still getting the error.
I am using IDLE to run scripts.
Can you provide any guidance?
Here is my Script to round raster cell values:
# Description: Converts each cell value of a raster to an integer by proper rounding
# Import required modules
# Python modules
import sys
sys.path.append("C:\OSGeo4W64\apps\qgis\python")
sys.path.append("C:\OSGeo4W64\apps\Python37\lib\site-packages")
sys.path.append("C:\OSGeo4W64\apps\qgis\python\qgis")
import time
import os
# Qgis modules
from qgis.core import *
import qgis.utils
from PyQt5.QtCore import QFileInfo, QSettings
import subprocess
subprocess.check_call([
"gdal_translate", "-of", "GTiff", "-ot", "Int32",
"H:/test/demtest1.tif", "H:/test/output/int.tif"
])
#done
print("done")
print("C:\OSGeo4W64\apps\qgis\python"), you will see that you've forgotten to either escape the backslash characters (by doubling them) or use unix-style right slashes. However, I tried fixing that and got another import error (when trying to loadqgis._core, despite_core.pydbeing in what seemed to me to be an appropriate location). So I can't give you a full answer. – Dan Getz Jan 03 '20 at 14:26PATH(note: not the same thing assystem.path). Did you try this? Also, since you have OSGeo4W installed, are you running IDLE from there? From what the answer I linked said, I would expect that might fix the problem, without needing to change anypaths orPATHs. – Dan Getz Jan 03 '20 at 14:38import subprocess. Are you trying to write code that works without opening QGIS? Or code to run inside a running QGIS? – Dan Getz Jan 03 '20 at 17:32