diff --git a/python/taichi/core/util.py b/python/taichi/core/util.py index 37b285f76e734..1361a87435ac1 100644 --- a/python/taichi/core/util.py +++ b/python/taichi/core/util.py @@ -49,12 +49,19 @@ def import_ti_core(tmp_dir=None): core.set_tmp_dir(locale_encode(tmp_dir)) -def locale_encode(s): +def locale_encode(path): try: import locale - return s.encode(locale.getdefaultlocale()[1]) - except TypeError: - return s.encode('utf8') + return path.encode(locale.getdefaultlocale()[1]) + except: + try: + import sys + return path.encode(sys.getfilesystemencoding()) + except: + try: + return path.encode() + except: + return path def is_ci(): @@ -159,8 +166,8 @@ def get_unique_task_id(): if get_os_name() != 'win': dll = ctypes.CDLL(get_core_shared_object(), mode=ctypes.RTLD_LOCAL) # The C backend needs a temporary directory for the generated .c and compiled .so files: - ti_core.set_tmp_dir(prepare_sandbox( - )) # TODO: always allocate a tmp_dir for all situations + ti_core.set_tmp_dir(locale_encode(prepare_sandbox( + ))) # TODO: always allocate a tmp_dir for all situations ti_core.set_python_package_dir(package_root()) os.makedirs(ti_core.get_repo_dir(), exist_ok=True) @@ -200,6 +207,10 @@ def get_unique_task_id(): from colorama import Fore, Back, Style print_red_bold("Taichi core import failed: ", end='') print(e) + print( + Fore.YELLOW + "check this page for possible solutions:\n" + "https://taichi.readthedocs.io/en/stable/install.html#troubleshooting" + + Fore.RESET) exit(-1) os.chdir(tmp_cwd) diff --git a/taichi/python/export_lang.cpp b/taichi/python/export_lang.cpp index 5a883ad56baa0..20deadcc5a7a7 100644 --- a/taichi/python/export_lang.cpp +++ b/taichi/python/export_lang.cpp @@ -574,8 +574,14 @@ void export_lang(py::module &m) { m.def("host_arch", host_arch); - m.def("set_lib_dir", [&](const std::string &dir) { compiled_lib_dir = dir; }); - m.def("set_tmp_dir", [&](const std::string &dir) { runtime_tmp_dir = dir; }); + m.def("set_lib_dir", [&](const std::string &dir) { + TI_INFO("set_lib_dir: [{}]", dir); + compiled_lib_dir = dir; + }); + m.def("set_tmp_dir", [&](const std::string &dir) { + TI_INFO("set_tmp_dir: [{}]", dir); + runtime_tmp_dir = dir; + }); m.def("get_runtime_dir", get_runtime_dir); m.def("get_commit_hash", get_commit_hash);