meetps/pytorch-semseg

python-cdo

xfry-lixuan opened this issue · 1 comments

When I run cdo = cdo(), it appears TypeError . How can you solve it?

# In
from cdo import Cdo
import os
import numpy as np
import re

cdo = Cdo()

# Out
TypeError                                 Traceback (most recent call last)
Input In [19], in <cell line: 6>()
      3 import numpy as np
      4 import re
----> 6 cdo = Cdo()

File ~\anaconda3\envs\CMIP6\lib\site-packages\cdo.py:187, in Cdo.__init__(self, cdo, returnNoneOnError, forceOutput, env, debug, tempdir, logging, logFile, cmd, options)
    184 self._cmd = cmd
    185 self._options = options
--> 187 self.operators         = self.__getOperators()
    188 self.noOutputOperators = [op for op in self.operators.keys() if 0 == self.operators[op]]
    189 self.returnNoneOnError = returnNoneOnError

File ~\anaconda3\envs\CMIP6\lib\site-packages\cdo.py:278, in Cdo.__getOperators(self)
    275 def __getOperators(self):  # {{{
    276   operators = {}
--> 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)

File ~\anaconda3\envs\CMIP6\lib\site-packages\cdo.py:78, in getCdoVersion(path2cdo, verbose)
     77 def getCdoVersion(path2cdo, verbose=False):
---> 78   proc = subprocess.Popen([path2cdo, '-V'], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
     79   ret = proc.communicate()
     81   cdo_help_stdout = ret[0].decode("utf-8")

File ~\anaconda3\envs\CMIP6\lib\subprocess.py:951, in Popen.__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, user, group, extra_groups, encoding, errors, text, umask)
    947         if self.text_mode:
    948             self.stderr = io.TextIOWrapper(self.stderr,
    949                     encoding=encoding, errors=errors)
--> 951     self._execute_child(args, executable, preexec_fn, close_fds,
    952                         pass_fds, cwd, env,
    953                         startupinfo, creationflags, shell,
    954                         p2cread, p2cwrite,
    955                         c2pread, c2pwrite,
    956                         errread, errwrite,
    957                         restore_signals,
    958                         gid, gids, uid, umask,
    959                         start_new_session)
    960 except:
    961     # Cleanup if the child failed starting.
    962     for f in filter(None, (self.stdin, self.stdout, self.stderr)):

File ~\anaconda3\envs\CMIP6\lib\subprocess.py:1360, in Popen._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_gid, unused_gids, unused_uid, unused_umask, unused_start_new_session)
   1358     args = list2cmdline([args])
   1359 else:
-> 1360     args = list2cmdline(args)
   1362 if executable is not None:
   1363     executable = os.fsdecode(executable)

File ~\anaconda3\envs\CMIP6\lib\subprocess.py:565, in list2cmdline(seq)
    563 result = []
    564 needquote = False
--> 565 for arg in map(os.fsdecode, seq):
    566     bs_buf = []
    568     # Add a space to separate this argument from the others

File ~\anaconda3\envs\CMIP6\lib\os.py:822, in _fscodec.<locals>.fsdecode(filename)
    816 def fsdecode(filename):
    817     """Decode filename (an os.PathLike, bytes, or str) from the filesystem
    818     encoding with 'surrogateescape' error handler, return str unchanged. On
    819     Windows, use 'strict' error handler if the file system encoding is
    820     'mbcs' (which is the default encoding).
    821     """
--> 822     filename = fspath(filename)  # Does type-checking of `filename`.
    823     if isinstance(filename, bytes):
    824         return filename.decode(encoding, errors)

TypeError: expected str, bytes or os.PathLike object, not NoneType

hjhjb commented