[Python] TypeError: environment can only contain strings

Discussão em 'Python' iniciado por Stack, Fevereiro 25, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using nipype for an image processing project. My python version is 3.6, and I got this error

    File "D:\softwares\Annoconda3\lib\site-
    packages\nipype\interfaces\base\core.py", line 750, in run_command
    close_fds=False,
    File "D:\softwares\Annoconda3\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
    File "D:\softwares\Annoconda3\lib\subprocess.py", line 997, in
    _execute_child
    startupinfo)
    TypeError: environment can only contain strings}


    Here are the codes that cause the error:

    def _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):
    """Execute program (MS Windows version)"""

    assert not pass_fds, "pass_fds not supported on Windows."

    if not isinstance(args, str):
    args = list2cmdline(args)

    # Process startup details
    if startupinfo is None:
    startupinfo = STARTUPINFO()
    if -1 not in (p2cread, c2pwrite, errwrite):
    startupinfo.dwFlags |= _winapi.STARTF_USESTDHANDLES
    startupinfo.hStdInput = p2cread
    startupinfo.hStdOutput = c2pwrite
    startupinfo.hStdError = errwrite

    if shell:
    startupinfo.dwFlags |= _winapi.STARTF_USESHOWWINDOW
    startupinfo.wShowWindow = _winapi.SW_HIDE
    comspec = os.environ.get("COMSPEC", "cmd.exe")
    args = '{} /c "{}"'.format (comspec, args)

    # Start the process
    try:
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
    # no special security
    None, None,
    int(not close_fds),
    creationflags,
    env,
    os.fspath(cwd) if cwd is not None else None,
    startupinfo)


    Can anyone help me with this problem?

    Continue reading...

Compartilhe esta Página