-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
windows下中文用户名造成的加载失败问题,Loading failure caused by Chinese user name under windows #428
Comments
Thanks so much for reporting! Yeah, a lot of Chinese users report Could anyone help confirm that without the Chinese characters, |
我试了,如果使用英文用户名是没有问题,只有中文用户名有这个问题 |
太好了,原来真的是这个导致的,谢谢你的实验。早期设计的时候我确实没有考虑到这个问题。根据你的输出
看起来应该是 谢谢! |
我编写了一个简单的测试小程序,结果显示: 我在网上查阅资料得知: 考虑将 python/taichi/core/util.py:39 修改为: lib_dir = os.path.join(package_root(), 'lib')
if get_os_name() == 'win':
lib_dir = lib_dir.encode('gbk') # 这里要能通过某个Windows的API获取路径编码格式就更好了
else:
lib_dir = lib_dir.encode('utf-8')
core.set_lib_dir(lib_dir) 希望能解决问题。 |
原来如此。指定 |
可以使用locale模块检测当前系统采用的默认编码格式,无论是否Windows: >>> import locale
>>> locale.getdefaultlocale()
('zh_CN', 'cp936') 其中CP936就是GBK,用起来完全一样: >>> '二三三'.encode('cp936')
b'\xb6\xfe\xc8\xfd\xc8\xfd'
>>> '二三三'.encode('gbk')
b'\xb6\xfe\xc8\xfd\xc8\xfd' cp=code page,是Windows系统对不同国家地区语言的一种编号,好比linux中的LC_*环境变量。比如936=GBK,65001=UTF-8。Windows用户可以通过cmd命令 考虑这样写: import locale
...
def locale_encode():
try: encoding = locale.getdefaultlocale()[1]
except: encoding = 'utf-8'
return x.encode(encoding)
...
core.set_lib_dir(locale_encode(lib_dir)) |
@archibate Cool! 这样听起来就比较系统的解决了这个问题。可否开一个PR加入这个解决方案? |
when a string is passed from python to C++, convert it into locale encoding, or it will fail if you try to pass it to OS API as file path.
when a string is passed from python to C++, convert it into locale encoding, or it will fail if you try to pass it to OS API as file path.
看起来这个问题已经解决了~ |
抱歉翻出来一个老帖,请问一下你当时是不是在用 Python 3.5? |
抱歉,刚刚才看到邮件。不是3.5,我当时用的是3.8 |
Describe the bug
使用windows操作系统,且用户名为中文,运行测试用例失败,显示加载.bc失败
Using windows operating system and user name in Chinese, running test case failed, showing failure to load .bc
Log/Screenshots
To Reproduce
If you have local commits (e.g. compile fixes before you reproduce the bug), please make sure you first make a PR to fix the build errors and then report the bug.
其实这不是个bug,是个环境问题,主要是因为正好我遇到了,也许之后也会有人遇到,所以这里提交一个Issue,也许其他语言的windows用户名也会出现类似的问题。
Non-English windows username can check if it fails to load
The text was updated successfully, but these errors were encountered: