文件的读写会消耗两次io,怎么避免这种操作呢?

如下代码给出例子:

import json
import cv2

# Generate JSON data
data = {"name": "John", "age": 30, "city": "New York"}
json_data = json.dumps(data)

# 将json转换为二进制格式
binary_json = json_data.encode("utf-8")

image_path = "/home/wst/1062916_1610182644569_0.jpg"
image = cv2.imread(image_path)

# 将图像转换为二进制格式
binary_data = cv2.imencode('.jpg', image)[1].tobytes()

记录遇到的错误及解决方法:

问题:

ImportError: libGL.so.1: cannot open shared object file: No such file or directory

解决方法:

sudo apt-get install ffmpeg libsm6 libxext6  -y