I know how to overwrite the TEMP variable path from the QGIS Interface, but I'm having problems doing the same thing via stand-alone Python scripts (using QgsApplication).

For example, I have the following script:

# Prepare QGIS environment
import sys
from qgis.core import *
from PyQt4.QtGui import *
app = QApplication([])
QgsApplication.setPrefixPath("E:\\QGIS\\apps\\qgis", True)

# Prepare processing framework 
from processing.core.Processing import Processing
import processing
from processing.tools import *

# Set variables
algorithm = "saga:rastercalculator"
input = "E:/input.tif"
addInput = None
formula = "ifelse(a=0, 0/0, ifelse(a<0, 0/0, a))"
useNoData = False
dataType = 7
result = "E:/output.tif"

# Run algorithm
processing.runalg(algorithm, input, addInput, formula, useNoData,
                  dataType, result)

# Exit QGIS

Along with the output, the script creates TEMP files in the following location:


How can I set a different path for the TEMP files?

1 Answer 1


You can overwrite the temporary folder where Processing writes files by calling os.environ before executing the algorithm (i.e., before calling processing.runalg()):

On Windows:

import os           # This line should go in the imports section
os.environ['TMP'] = "E:\\my\\own\\tmp\\folder\\"

On GNU/Linux:

import os              # This line should go in the imports section
os.environ['TMPDIR'] = "/my/own/tmp/folder/"

The good part is that using os.environ you won't set the environment variable TEMP/TMP/TMPDIR permanently. It works for the current Python script/application, so you won't mess other applications up.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.