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"", line 3,inimport numpy File"c:\users\jakub\miniconda3\lib\site-packages\numpy\__init__.py", line 165,infrom 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
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.
回答1:
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:
check the latter 3 especially, and replace any non-escaped backslashes ( \ ) with either escaped ones ( \\ ) or forward slashes
回答2:
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.
回答3:
I just now downloaded keras, and put this single line in a python script:
from keras.layers importDense
When I try to run it, I get the error message: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape.
I am using Anaconda with a virtual environment for Python 3.5. Seems like some path names within Keras throw this error. Is there any work around without searching and editing every source file ?
回答4:
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