0

I'm passing a simple gdal_calc.py command line argument to os.system() in a python script. However when I run the script, nothing is generated and the gdal_calc.py source script opens automatically:

enter image description here

I have gdal installed in my conda environment, and the gdal command line call works from the terminal when called directly. My python code looks like this:

command_str = 'gdal_calc.py -A data/raster1.tif -B data/raster2.tif -- outfile="test.tif" --calc="A/B"' os.system(command_str) 

I'm new to working on a windows machine and this pattern worked reliably on my mac, so wondering if this is an operating system issue? I also have this added to my PATH environment variables:
'C:\Users<firstname.lastname>\Miniconda3'

3
  • It looks like your default 'open with' for files of type *.py is Conda, can you try call python.exe first and pass the rest as args (like command_str = 'C:/path/to/python.exe gdal_calc.py -A data/raster1.tif -B data/raster2.tif...) or set your default Windows 'open with' to python.exe. Commented Oct 27, 2022 at 6:17
  • interesting idea, I tried adding python.exe full path and gdal_calc.py full path, but get a new error: "ufunc 'multiply' did not contain a loop with signature matching types (dtype('int32'), dtype('<U3')) -> None". When I take that command_str variable (dropping the python.exe full path) and run in command line everything works great, so I know it's not the input datasets. Commented Oct 27, 2022 at 16:23
  • That sounds like a new problem worthy of a new question, but first can you put your command into a batch file and try calling that from os.system, it could be your GDAL system paths are different while executing the python code. Commented Oct 28, 2022 at 4:50

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.