Python 'unresolved import keyboard'。 Py安装程序

Python 'unresolved import keyboard'. PyInstaller

我有一个简单的python:

import requests
import keyboard
resp = requests.get('http://www.google.com')
keyboard.send('A')

这是一个例子。

当我 运行 这段代码与 python main.py 一切正常,但在 VSCode 第二行是下划线,因为 "unresolved import 'keyboard' " 第一行没有下划线。 Pyinstaller 是最大的问题。生成 .exe 文件后不起作用,因为: ModuleNotFoundError: No module named "keyboard" 两个模块都已安装

听起来您需要配置 VsCode 以使用与安装该模块的解释器相同的解释器,我不是 VsCode 的拥护者,所以我不使用它但我知道这是可能的。这可能对您有所帮助:https://code.visualstudio.com/docs/python/environments

To select an specific environment, use the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P).