且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

导入numpy引发错误:SyntaxError:(unicode错误)'unicodeescape'编解码器无法解码位置2-3中的字节:截断的\ uXXXX转义

更新时间:2022-05-13 18:39:01

当conda安装软件包时,它将替换前缀以使内容可重定位.不幸的是,它不能智能地转义反斜杠,因此在Windows上,这些未转义的反斜杠会导致您看到错误.

When conda installs packages, it replaces the prefix, to make things relocatable. Unfortunately, it does not intelligently escape backslashes, so on Windows, these unescaped backslashes lead to the error you see.

在最新版本的conda中,我们在前缀替换中使用正斜杠,而这个问题就消失了.如果您可以更新conda,请执行此操作.如果不是,则numpy在以下文件中具有前缀:

In recent versions of conda, we use forward slashes in prefix replacement, and this issue goes away. If you can update conda, go do that. If not, numpy has prefixes in the following files:

"Lib/site-packages/numpy/distutils/site.cfg"
"Scripts/f2py.py"
"Lib/site-packages/numpy/config.py"
"Lib/site-packages/numpy/distutils/config.py"

特别检查后3个,并用转义的(\\)或正斜杠替换所有未转义的反斜杠(\)

check the latter 3 especially, and replace any non-escaped backslashes ( \ ) with either escaped ones ( \\ ) or forward slashes