Project

General

Profile

cdo (python 3) on jupyter notebook?

Added by Jonas Ardö over 2 years ago

Trying to run cdo from a jupyter notebook on windows 10 (without success):

---------------------------------------------------------------------------------
!pip3 install cdo
from cdo import *
cdo = Cdo()
ifile= 'G:/Undervisning/2022/NGEN21/test/1950_and_2021.nc'
cdo.infov(input=ifile) #python
cdo.showlevels(input=ifile)
---------------------------------------------------------------------------------

and below is the output I get.
Any special configuration needed to get cdo to work in a jupyter notebook?
Any example?
Regards
/Jonas


Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: cdo in c:\users\jonas.ardo\appdata\roaming\python\python37\site-packages (1.5.6)
Requirement already satisfied: six in c:\program files\arcgis\pro\bin\python\envs\arcgispro-py3\lib\site-packages (from cdo) (1.15.0)

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-26-1b7208c0bdca> in <module>
1 get_ipython().system('pip3 install cdo')
2 from cdo import *
----> 3 cdo = Cdo()
4 ifile= 'G:/Undervisning/2022/NGEN21/test/1950_and_2021.nc'
5 cdo.infov(input=ifile) #python

~\AppData\Roaming\Python\Python37\site-packages\cdo.py in init(self, cdo, returnNoneOnError, forceOutput, env, debug, tempdir, logging, logFile, cmd, options)
185 self._options = options
186
--> 187 self.operators = self.__getOperators()
188 self.noOutputOperators = [op for op in self.operators.keys() if 0 == self.operators[op]]
189 self.returnNoneOnError = returnNoneOnError

~\AppData\Roaming\Python\Python37\site-packages\cdo.py in __getOperators(self)
276 operators = {}
277
--> 278 version = parse_version(getCdoVersion(self.CDO))
279 if (version < parse_version('1.7.2')):
280 proc = subprocess.Popen([self.CDO, '-h'], stderr=subprocess.PIPE, stdout=subprocess.PIPE)

~\AppData\Roaming\Python\Python37\site-packages\cdo.py in getCdoVersion(path2cdo, verbose)
76 # some helper functions without side effects {{{
77 def getCdoVersion(path2cdo, verbose=False):
---> 78 proc = subprocess.Popen([path2cdo, '-V'], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
79 ret = proc.communicate()
80

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\subprocess.py in init(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
798 c2pread, c2pwrite,
799 errread, errwrite,
--> 800 restore_signals, start_new_session)
801 except:
802 # Cleanup if the child failed starting.

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
1146
1147 if not isinstance(args, str):
-> 1148 args = list2cmdline(args)
1149
1150 # Process startup details

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\subprocess.py in list2cmdline(seq)
553 result.append(' ')
554
--> 555 needquote = (" " in arg) or ("\t" in arg) or not arg
556 if needquote:
557 result.append('"')

TypeError: argument of type 'NoneType' is not iterable


Replies (3)

RE: cdo (python 3) on jupyter notebook? - Added by Karin Meier-Fleischer over 2 years ago

Hi Jonas,

I recommend to use conda or apt-get to install cdo/python-cdo. On the installation page https://code.mpimet.mpg.de/projects/cdo/wiki/Win32 pip is not mentioned.

RE: cdo (python 3) on jupyter notebook? - Added by Ralf Mueller over 2 years ago

hi Jonas!

you seem to work under Windows natively. AFAIK there is no CDO binary, that works in that environment.

you have to use ether the Linux Subsystem or cygwin in that case.

cheers
ralf

RE: cdo (python 3) on jupyter notebook? - Added by Ralf Mueller over 2 years ago

Ah, I cannot comment on jupyterhub on windows. But a plain python script I can work with.

    (1-3/3)