【发布时间】:2018-02-03 14:36:23
【问题描述】:
我正在尝试读取文件名包含西里尔字符的图像文件。
ls /home/atin/test
ОД Д.bmp
现在我正在尝试在 python 3 中读取“ОД Д.bmp”
image_path='/home/atin/test/ОД Д.bmp'
import matplotlib.pyplot as plt
sample_image=plt.imread(image_path)
但我收到此错误。
SystemError: <built-in function read_png> returned NULL without setting an error
但os.listdir('/home/atin/test') 给出以下输出
['\udcd0\udc9e\udcd0\udc94\udcd0\udc94.bmp']
如何将上述输出解码为原始文件名 ОД Д.bmp。 我在这里在 ubuntu 中使用 python 3.6。
【问题讨论】:
-
ОД р1与ОД Д不同。该错误不会立即向我表明文件名是这里的问题。 -
sys.getfilesystemencoding()返回什么?这可能是一个错误的值。这是什么操作系统? -
那些
\u转义序列是低代理点。这可能表明文件系统编码不是 UTF-8,但 Python 需要 UTF-8。然后通过 surrogateescape 错误处理程序保留字节,但这意味着原始数据是b'\xd0\x9e\xd0\x94 \xd0\x94.bmp',这是 有效的 UTF-8。 -
我已经进行了必要的编辑,很抱歉输入错误。但错误仍然是一样的。
-
UNIX 命令
locale产生什么?对于给定的文件系统,这几乎肯定是错误的。
标签: python python-3.x unicode filepath