Project

General

Profile

cdo in python can't find commands, "cdo: command not found"

Added by Chad Burton over 6 years ago

Hi, I'm trying to use the cdo python wrapper to execute a bunch of cdo commands within a python script that is running on a linux environment. I have CDO 1.7.1 installed and CDO-py 1.3.5 (using python3.x) When I run the following code I get the error: "returncode:127) /bin/sh: cdo: command not found"

from cdo import *
cdo=Cdo()
cdo.debug = True
ifile1 = 'ls7.nc'
ifile2 = 'ls8.nc'
ofile = 'allobs.nc'
cdo.mergetime(input=" ".join((ifile1,ifile2)), output=ofile)

Any ideas why the command can't be found?

The debug output looks like this:
  1. DEBUG - start =============================================================
    CALL :cdo -O mergetime ls7.nc ls8.nc allobs.nc
    STDOUT:
    STDERR:
    /bin/sh: cdo: command not found
  1. DEBUG - end ===============================================================
    RETURNCODE:127
    Error in calling operator mergetime with:

cdo -O mergetime ls7.nc ls8.nc allobs.nc<<<

STDOUT:
STDERR:/bin/sh: cdo: command not found


Replies (3)

RE: cdo in python can't find commands, "cdo: command not found" - Added by Chad Burton over 6 years ago

ok so I solved this by explicitly specifying the file path location of cdo.exe, its a bit of hack but its probably easier than updating the source code.

in the terminal run: which cdo

then take the output string and update 'cdo.CDO'

cdo.CDO = "/apps/cdo/1.7.1/bin/cdo"

the overall code looks like this:

from cdo import *
cdo=Cdo()
cdo.CDO = '/apps/cdo/1.7.1/bin/cdo'
ifile1 = 'ls7.nc'
ifile2 = 'ls8.nc'
ofile = 'allobs.nc'
cdo.mergetime(input=" ".join((ifile1,ifile2)), output=ofile)

RE: cdo in python can't find commands, "cdo: command not found" - Added by Ralf Mueller over 6 years ago

Hi Chad!

which cdo.py version do you use on what of system?

cheers
ralf

RE: cdo in python can't find commands, "cdo: command not found" - Added by Ralf Mueller over 6 years ago

and could you run the latest development version from https://github.com/Try2Code/cdo-bindings?

problems is, that another user reported on this and I fixed it on a MacOS system until it worked, but I cannot test this on different systems like this. So a test by you would really help me in getting confident with my fix

thx in advance
ralf

    (1-3/3)