diff --git a/vm/src/stdlib/os.rs b/vm/src/stdlib/os.rs index e5355289b..bb6338073 100644 --- a/vm/src/stdlib/os.rs +++ b/vm/src/stdlib/os.rs @@ -457,8 +457,26 @@ fn os_unsetenv(key: Either, vm: &VirtualMachine) -> PyR fn _os_environ(vm: &VirtualMachine) -> PyDictRef { let environ = vm.ctx.new_dict(); - for (key, value) in env::vars() { - environ.set_item(&key, vm.new_str(value), vm).unwrap(); + #[cfg(unix)] + { + use std::os::unix::ffi::OsStringExt; + for (key, value) in env::vars_os() { + environ + .set_item( + &vm.ctx.new_bytes(key.into_vec()), + vm.ctx.new_bytes(value.into_vec()), + vm, + ) + .unwrap(); + } + } + #[cfg(windows)] + { + for (key, value) in env::vars() { + environ + .set_item(&vm.new_str(key), vm.new_str(value), vm) + .unwrap(); + } } environ }