[GIS] Errno 13 “Permission Denied” when running tools and plugins on QGIS

grasspermissionerrorqgisqgis-processingsaga

I am having an issue with multiple tools when using QGIS where I am constantly getting PermissionError: [Errno 13] Permission denied type errors.

A lot of it seems to be associated with tools that use the GRASS or SAGA libraries, but it is also happening with some of the core QGIS Python scripts.

The example below is the error output from when I tried to run a plugin tool that calculates flood depth:

Traceback (most recent call last):
File "/Applications/QGIS3.10.app/Contents/MacOS/../Resources/python/plugins/processing/algs/grass7/Grass7Algorithm.py", line 409, in processAlgorithm
Grass7Utils.startGrassSession()
File "/Applications/QGIS3.10.app/Contents/MacOS/../Resources/python/plugins/processing/algs/grass7/Grass7Utils.py", line 462, in startGrassSession
Grass7Utils.createTempMapset()
File "/Applications/QGIS3.10.app/Contents/MacOS/../Resources/python/plugins/processing/algs/grass7/Grass7Utils.py", line 301, in createTempMapset
folder = Grass7Utils.grassMapsetFolder()
File "/Applications/QGIS3.10.app/Contents/MacOS/../Resources/python/plugins/processing/algs/grass7/Grass7Utils.py", line 277, in grassMapsetFolder
folder = os.path.join(Grass7Utils.grassDataFolder(), 'temp_location')
File "/Applications/QGIS3.10.app/Contents/MacOS/../Resources/python/plugins/processing/algs/grass7/Grass7Utils.py", line 288, in grassDataFolder
mkdir(tempfolder)
File "/Applications/QGIS3.10.app/Contents/MacOS/../Resources/python/plugins/processing/tools/system.py", line 103, in mkdir
mkdir(head)
File "/Applications/QGIS3.10.app/Contents/MacOS/../Resources/python/plugins/processing/tools/system.py", line 103, in mkdir
mkdir(head)
File "/Applications/QGIS3.10.app/Contents/MacOS/../Resources/python/plugins/processing/tools/system.py", line 103, in mkdir
mkdir(head)
[Previous line repeated 1 more time]
File "/Applications/QGIS3.10.app/Contents/MacOS/../Resources/python/plugins/processing/tools/system.py", line 105, in mkdir
os.mkdir(newdir)
PermissionError: [Errno 13] Permission denied: '/var/folders/pn'

There were errors executing the algorithm.
There were errors executing the algorithm.
Execution failed after 2.85 seconds

How do I get past this "Permission Denied" error? None of the stuff I have found so far online has provided a clear solution to the problem.

Best Answer

I'm no expert with QGIS, but it looks like the python process is trying to make a new directory in your var folder, which it won't have permissions to do. I just tried it out directly in python on my mac to confirm:

>>> import os
>>> os.makedirs('/var/folders/test')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/os.py", line 223, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/var/folders/test'

Can you try changing where you're saving the output of this process? If the disk write that it wants to do here is to save an intermediary step though I'm not really sure what to tell you, besides run the process directly from terminal yourself with GDAL