ModuleNotFoundError: No module named 'qrcode'
W File "/usr/lib/python3/dist-packages/pip/_internal/resolution/resolvelib/candidates.py", line 222, in _prepare dist = self._prepare_distribution() File "/usr/lib/python3/dist-packages/pip/_internal/resolution/resolvelib/candidates.py", line 307, in _prepare_distribution return self._factory.preparer.prepare_linked_requirement( File "/usr/lib/python3/dist-packages/pip/_internal/operations/prepare.py", line 480, in prepare_linked_requirement return self._prepare_linked_requirement(req, parallel_builds) File "/usr/lib/python3/dist-packages/pip/_internal/operations/prepare.py", line 503, in _prepare_linked_requirement local_file = unpack_url( File "/usr/lib/python3/dist-packages/pip/_internal/operations/prepare.py", line 253, in unpack_url file = get_http_url( File "/usr/lib/python3/dist-packages/pip/_internal/operations/prepare.py", line 130, in get_http_url from_path, content_type = download(link, temp_dir.path) File "/usr/lib/python3/dist-packages/pip/_internal/network/download.py", line 163, in __call__ for chunk in chunks: File "/usr/lib/python3/dist-packages/pip/_internal/cli/progress_bars.py", line 168, in iter for x in it: File "/usr/lib/python3/dist-packages/pip/_internal/network/utils.py", line 64, in response_chunks for chunk in response.raw.stream( File "/usr/share/python-wheels/urllib3-1.26.5-py2.py3-none-any.whl/urllib3/response.py", line 576, in stream data = self.read(amt=amt, decode_content=decode_content) File "/usr/share/python-wheels/urllib3-1.26.5-py2.py3-none-any.whl/urllib3/response.py", line 541, in read raise IncompleteRead(self._fp_bytes_read, self.length_remaining) File "/usr/lib/python3.9/contextlib.py", line 135, in __exit__ self.gen.throw(type, value, traceback) File "/usr/share/python-wheels/urllib3-1.26.5-py2.py3-none-any.whl/urllib3/response.py", line 443, in _error_catcher raise ReadTimeoutError(self._pool, None, "Read timed out.") urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='www.piwheels.org', port=443): Read timed out. Traceback (most recent call last): File "/home/pi/.edublocks/output.py", line 149, in <module> import qrcode ModuleNotFoundError: No module named 'qrcode'
1
from PIL import Image import subprocess # 安装qrcode包 subprocess.call(['pip', 'install', 'image']) subprocess.call(['pip', 'install', 'qrcode']) import qrcode # 需要生成二维码的内容 data = "https://www.example.com" # 生成QRCode对象 qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_H, box_size=10, border=4, ) qr.add_data(data) qr.make(fit=True) img = qr.make_image(fill_color="black", back_color="white") # 控制二维码图片宽高小于240 max_size = 240 width, height = img.size if width > max_size: ratio = max_size/width width = max_size height = int(ratio*height) elif height > max_size: ratio = max_size/height height = max_size width = int(ratio*width) # 生成的二维码图片宽高最大为240*240 img = img.resize((width,height)) path = "/home/pi/xgoPictures/" img.save(path+'qrcode.png') # 显示路径下文件名 def showfiles(path): files = os.listdir(path) for file in files: print(file) pass showfiles(path)