today Python digital image processing installed anaconda, using its default editor spyder. But an error occurred while running a simple program like the one shown below. The error is:
SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
where the simple test code is:
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 24 21:31:25 2017
@author: harchi
"""
from skimage import io
img=io.imread('C:\Users\harchi\Desktop\图像处理\skeleton.bmp')
io.imshow(img)
the cause of the error is: imread(‘C:\Users\harchi\Desktop\ skeleton. BMP ‘) the “\” in the line represents an escape in Python.
the solution, of course, is not to let “\” stand for escape. So you can:
1, prefix the string with r or r, i.e. imread(r’C:\Users\harchi\Desktop\ skeleton. BMP ‘) where r or r denotes an unescaped string in python.
2, before “\” with “\” to achieve escape. Namely: imread (‘ C: \ \ Users \ \ harchi \ \ Desktop \ \ \ \ skeleton image processing BMP ‘) </ span> </ p>
</ span> 3, “\” change into “/”, namely: the imread (‘ C:/Users \ harchi/Desktop/image processing/skeleton BMP ‘) </ span> </ p>
</ span> finally: add python string prefix knowledge:
1, prefix the string with r or r to indicate that the string is an unescaped original string.
2, prefix a string with u or u to indicate that the string is unicode.
Read More:
- python SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: trunca
- SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3: truncated \UX
- SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3: truncated \UX
- Syntax Error: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position resolution
- How to solve the problem of syntax error: (Unicode error)’unicodescape ‘codec can’t decode bytes in position 2-3: truncat
- When reading the CSV file with Python 3, the Unicode decodeerror: ‘UTF-8’ codec can’t decode byte 0xd0 in position 0: invalid con appears
- Unicode decodeerror: ‘UTF-8’ codec can’t decode byte 0xd3 in position 238: invalid continuation B
- Successfully resolved Unicode decodeerror: ‘UTF-8’ codec can’t decode byte 0xd3 in position 238: invalid continuation B
- Unicode decodeerror: ‘UTF-8’ codec can’t decode byte 0x80 in position 3131: invalid start byte solution
- Solution of Unicode decodeerror -‘utf-8 ‘codec can’t decode byte 0xc4 in position 0 – invalid continuation byte
- Run Python file for the first time with eclipse / pydev: “UTF-8 ‘codec can’t decode byte 0xc4 in position
- Solve the ‘UTF-8’ codec can’t decode byte 0xe9 in position 3114: invalid continuation byte error
- ‘ascii‘ codec can‘t decode byte 0x90 in position 614: ordinal not in range(128)
- UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xc3 in position 54: invalid continuation byte
- UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xd6 in position 3089: invalid continuation byte
- [system]SyntaxError: Unexpected token u in JSON at position 0
- UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 0-2: ordinal not in range(128)
- Unicode encodeerror: ‘GBK’ codec can’t encode character solution
- 12304;388382;3906442nd 123057 SyntaxError and unicode error and 8216215;
- Unicode encodeerror encountered in Python 3