导入包会导致Anaconda中的Unicode错误

时间:2016-10-13 05:37:42

标签: python anaconda

在我输入的程序中:将matplotlib导入为pt,我收到以下错误:

  File "C:\Users\hh\Anaconda3\lib\site-packages\numpy\__config__.py", line 5
    blas_mkl_info={'libraries': ['mkl_core_dll', 'mkl_intel_lp64_dll', 'mkl_intel_thread_dll'], 'library_dirs': ['C:\Users\hh\Anaconda3\\Library\\lib'], 'include_dirs': ['C:\Users\hh\Anaconda3\\Library\\include'], 'define_macros': [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]}
                                                                                                                ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

为什么会发生这种情况以及我可以采取哪些措施来改变这种情况?

这是它所指的文件:

# This file is generated by C:\Minonda\conda-bld\numpy-1.11_1475607650950\work\numpy-1.11.2\setup.py
# It contains system_info results at the time of building this package.
__all__ = ["get_info","show"]

blas_mkl_info={'libraries': ['mkl_core_dll', 'mkl_intel_lp64_dll', 'mkl_intel_thread_dll'], 'library_dirs': ['C:\Users\hh\Anaconda3\\Library\\lib'], 'include_dirs': ['C:\Users\hh\Anaconda3\\Library\\include'], 'define_macros': [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]}
openblas_lapack_info={}
blas_opt_info={'libraries': ['mkl_core_dll', 'mkl_intel_lp64_dll', 'mkl_intel_thread_dll'], 'library_dirs': ['C:\Users\hh\Anaconda3\\Library\\lib'], 'include_dirs': ['C:\Users\hh\Anaconda3\\Library\\include'], 'define_macros': [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]}
lapack_opt_info={'libraries': ['mkl_core_dll', 'mkl_intel_lp64_dll', 'mkl_intel_thread_dll'], 'library_dirs': ['C:\Users\hh\Anaconda3\\Library\\lib'], 'include_dirs': ['C:\Users\hh\Anaconda3\\Library\\include'], 'define_macros': [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]}
lapack_mkl_info={'libraries': ['mkl_core_dll', 'mkl_intel_lp64_dll', 'mkl_intel_thread_dll'], 'library_dirs': ['C:\Users\hh\Anaconda3\\Library\\lib'], 'include_dirs': ['C:\Users\hh\Anaconda3\\Library\\include'], 'define_macros': [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]}

def get_info(name):
    g = globals()
    return g.get(name, g.get(name + "_info", {}))

def show():
    for name,info_dict in globals().items():
        if name[0] == "_" or type(info_dict) is not type({}): continue
        print(name + ":")
        if not info_dict:
            print("  NOT AVAILABLE")
        for k,v in info_dict.items():
            v = str(v)
            if k == "sources" and len(v) > 200:
                v = v[:60] + " ...\n... " + v[-60:]
            print("    %s = %s" % (k,v))

1 个答案:

答案 0 :(得分:1)

你的路径字符串中缺少(几个)转义反斜杠:

'C:\Users\hh\Anaconda3\\Library\\lib'

这里python将尝试将\U解释为unicode转义序列的开头(参见例如https://docs.python.org/2/reference/lexical_analysis.html#string-literals)。

正如您在此字符串的部分内容中所做的那样,您应该将\替换为\\

'C:\\Users\\hh\\Anaconda3\\Library\\lib'

或使用原始字符串:

r'C:\Users\hh\Anaconda3\Library\lib'

修改 我现在才意识到,这是由numpy / anaconda创建的文件而不是你自己。所以这可能值得为他们买票...我猜...