diff --git a/share/spack/setup-env.sh b/share/spack/setup-env.sh
index 21a7e0034508aa452ac0b9c9040f23f9c17644b7..38bcac03a9557d6fccdfe935d43777d656ed65b9 100755
--- a/share/spack/setup-env.sh
+++ b/share/spack/setup-env.sh
@@ -236,9 +236,16 @@ fi;
 #
 # Set up modules and dotkit search paths in the user environment
 #
-_sp_sys_type=$(spack-python -c 'print(spack.architecture.sys_type())')
-_sp_dotkit_root=$(spack-python -c "print(spack.util.path.canonicalize_path(spack.config.get_config('config').get('module_roots', {}).get('dotkit')))")
-_sp_tcl_root=$(spack-python -c "print(spack.util.path.canonicalize_path(spack.config.get_config('config').get('module_roots', {}).get('tcl')))")
+
+_python_command=$(printf  "%s\\\n%s\\\n%s" \
+"print(\'_sp_sys_type={0}\'.format(spack.architecture.sys_type()))" \
+"print(\'_sp_dotkit_root={0}\'.format(spack.util.path.canonicalize_path(spack.config.get_config(\'config\').get(\'module_roots\', {}).get(\'dotkit\'))))" \
+"print(\'_sp_tcl_root={0}\'.format(spack.util.path.canonicalize_path(spack.config.get_config(\'config\').get(\'module_roots\', {}).get(\'tcl\'))))"
+)
+
+_assignment_command=$(spack-python -c "exec('${_python_command}')")
+eval ${_assignment_command}
+
 _spack_pathadd DK_NODE    "${_sp_dotkit_root%/}/$_sp_sys_type"
 _spack_pathadd MODULEPATH "${_sp_tcl_root%/}/$_sp_sys_type"