gpt4 book ai didi

python - 导入包导致 Anaconda 中出现 Unicode 错误

转载 作者:太空宇宙 更新时间:2023-11-03 16:04:12 26 4
gpt4 key购买 nike

在我的程序中,当我输入: import matplotlib as 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))

最佳答案

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

'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 创建的文件,而不是您自己创建的文件。所以我想这对他们来说可能值得买票......

关于python - 导入包导致 Anaconda 中出现 Unicode 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40013060/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com