导入numpy引发错误:SyntaxError:(unicode错误)'unicodeescape'编解码器无法解码位置2-3中的字节:截断的\ uXXXX转义 [英] Import numpy throws error: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \uXXXX escape

查看:601
本文介绍了导入numpy引发错误:SyntaxError:(unicode错误)'unicodeescape'编解码器无法解码位置2-3中的字节:截断的\ uXXXX转义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Windows 10下安装了pyzominiconda,并使用conda install安装了numpymatplotlib.但是当我尝试运行

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 

我收到此错误:

Traceback (most recent call last):
  File "<tmp 1>", line 3, in <module>
    import numpy
  File "c:\users\jakub\miniconda3\lib\site-packages\numpy\__init__.py", line 165, in <module>
    from numpy.__config__ import show as show_config
  File "c:\users\jakub\miniconda3\lib\site-packages\numpy\__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:\users\jakub\miniconda3\\Library\\include'], 'library_dirs': ['c:\users\jakub\miniconda3\\Library\\lib']}
                                                                                                                                                                                                       ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \uXXXX escape

我的代码和目录结构中都没有任何非标准字符...我读过很多帖子都提到了UTF-8的类似问题,但这与初始导入期间的情况有所不同.

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.

推荐答案

当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

这篇关于导入numpy引发错误:SyntaxError:(unicode错误)'unicodeescape'编解码器无法解码位置2-3中的字节:截断的\ uXXXX转义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆