Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
614 views
in Technique[技术] by (71.8m points)

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

I have installed pyzo and miniconda under Windows 10 and installed numpy and matplotlib using conda install. But when I'm trying to run

import numpy as np 
import matplotlib.pyplot as plt 

I'm getting this error:

Traceback (most recent call last):
  File "<tmp 1>", line 3, in <module>
    import numpy
  File "c:usersjakubminiconda3libsite-packages
umpy\__init__.py", line 165, in <module>
    from numpy.__config__ import show as show_config
  File "c:usersjakubminiconda3libsite-packages
umpy\__config__.py", line 5
    lapack_mkl_info={'libraries': ['mkl_lapack95_lp64', 'mkl_core_dll', 'mkl_intel_lp64_dll', 'mkl_intel_thread_dll'], 'define_macros': [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)], 'include_dirs': ['c:usersjakubminiconda3\Library\include'], 'library_dirs': ['c:usersjakubminiconda3\Library\lib']}
                                                                                                                                                                                                       ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated uXXXX escape

I do not have any non-standard character either in my code nor in the directory structure...I have read many posts referring to similar problems with UTF-8 but this is different as it happens during the initial import.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...