Import error numpy: SyntaxError: (error in unicode) Encoding "unicodeescape" cannot decode bytes at position 2-3: truncated \ uXXXX escape

I installed pyzo and miniconda in Windows 10 and found numpy and matplotlib using conda install . But when I try to run

 import numpy as np import matplotlib.pyplot as plt 

I get this error:

 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 

I have no non-standard character in either my code or the directory structure ... I read a lot of posts citing similar problems with UTF-8, but this is different as it happens during the initial import.

+6
source share
4 answers

When conda installs packages, it replaces the prefix to make things moveable. Unfortunately, it does not allow you to avoid backslashes, so on Windows these irreplaceable backslashes lead to the error you see.

In recent versions of conda, we use slashes when replacing the prefix, and this problem goes away. If you can upgrade the condo, do it. 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 last 3 especially and replace any non-exclusive backslashes (\) with either escaped (\\) or with a slash

+9
source

So, for people having problems in

 import numpy 

using Windows 10 + Anaconda:

I replaced all single '\' with double '\\' in

 \Lib\site-packages\numpy\__config__.py 

I could import numpy after that.

+3
source

I just downloaded keras and put this single line in a python script:

 from keras.layers import Dense 

When I try to run it, I get the error message: SyntaxError: (unicode error) 'unicodeescape' codec cannot decode bytes at position 2-3: truncated \ UXXXXXXXX escape.

I am using Anaconda with a virtual environment for Python 3.5. It seems that some path names inside Keras are throwing this error. Is there any work without searching and editing each source file?

0
source

Here's how it worked for me: double \ before and after the user’s word.

For example: \\users\\admin\anaconda3\sample.wav

I am using python 3.6 for windows 7

I don’t know why the message stores only one word and after the user’s word in the way

0
source

All Articles