ModuleNotFoundError:Python 3.9.13 中没有名为“qrcode”的模块

问题描述 投票:0回答:1

我正在 VScode 中构建 QR 码生成器。

我已经使用

pip install qrcode

在我的终端中安装了最新的 qrcode 7.4.2 库版本
# Import the QR Code Library
import qrcode

# Accept the URL as Input
url = input("Enter the URL: ")

# Generate the QR Code
img = qrcode.make(url)

# Obtain the Filename
filename = input("Enter filename to save QR code (include extension): ")

# Save the QR Code
img.save(filename)
print(f"QR code saved as {filename}")

然而, 当我在 VScode 终端中运行代码时。我不断收到此错误:

Traceback (most recent call last):
  File "c:\Users\Genva\Desktop\Personal Projects 2024\Beginner Projects\qr_generator.py", line 2, in <module>
    import qrcode
ModuleNotFoundError: No module named 'qrcode'

我已经安装/使用了这些代码片段:

  • pip3安装二维码
  • python3,然后输入 import qrcode
  • pip3安装pyqrcode
  • import qrcode from PIL import Image
  • pip3 安装 Pillow
  • python3 -m pip install Pillow
  • py -m pip 安装枕头
  • python -m pip install --升级 pip
  • pip 安装枕头

最后,我尝试修复路径。 我检查了 pip 是否安装在正确的路径中以及我的系统脚本是否能够找到它。

这些解决方案都不起作用,我仍然遇到相同的“ModuleNotFoundError:没有名为“qrcode”的模块”问题。

python python-3.x qr-code
1个回答
0
投票

一个有点创可贴的解决方案,但使用

sys.executable
确保您使用的是 VS Code 正在使用的 python 安装:

import sys
import subprocess
package = input("package name: ")
subprocess.check_call([sys.executable, "-m", "pip", "install", package])
© www.soinside.com 2019 - 2024. All rights reserved.