Import numpy throws error: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \\uXXXX escape

拜拜、爱过 提交于 2019-11-29 04:27:55

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.

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"

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

So, for people having trouble in

import numpy

using Windows 10 + Anaconda:

I replaced all single '\' to double '\\' in

\Lib\site-packages\numpy\__config__.py

I could import numpy after that.

user7907221

This is how it worked for me: double \ before and after users word.

For example: \\users\\admin\anaconda3\sample.wav

I am using python 3.6 on Windows 7

Not sure why the post keeps only one \ after and before users word in the path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!