“Import pyfirmata could not be resolved” 可以翻译为 “导入 pyfirmata 无法解析”。

huangapple go评论58阅读模式
英文:

Import pyfirmata could not be resolved

问题

I tried importing pyfirmata module and it does not recognise it. This is th error i get when hovering over it: "Import "pyfirmata" could not be resolved Pylance(reportMissingImports)"
This is the code:

from pyfirmata import Arduino, util
import time

board = Arduino("COM5")

# print(board.get_firmata_version())

for x in range(10):
    board.digital[13].write(1)
    time.sleep(0.2)
    board.digital[13].write(0)
    time.sleep(0.5)

I tried reinstalling the module, changing the com, running it with the board plugged and unplugged.

英文:

I tried importing pyfirmata module and it does not recognise it. This is th error i get when hovering over it: "Import "pyfirmata" could not be resolved Pylance(reportMissingImports)"
This is the code:

from pyfirmata import Arduino, util
import time

board = Arduino("COM5")

# print(board.get_firmata_version())

for x in range(10):
    board.digital[13].write(1)
    time.sleep(0.2)
    board.digital[13].write(0)
    time.sleep(0.5)


I tried reinstalling the module, changing the com, running it with the board plugged and unplugged.

答案1

得分: 1

已成功安装 pyFirmata,使用命令 pip install pyFirmata,似乎您可能遇到了与 Visual Studio Code 中 Pylance 扩展相关的 Python 路径配置问题。

为解决此问题,您可以通过在 Visual Studio Code 中打开命令面板,使用快捷键 Ctrl+Shift+P,然后键入 settings.json 并从搜索结果中选择它来设置正确的路径。这将打开 settings.json 文件,您可以添加以下代码片段:

{
    "python.defaultInterpreterPath": "C:/Users/Maisu/AppData/Local/Programs/Python/Python311/python.exe"
}

请确保在代码片段中替换路径为您的 Python 解释器正确安装的路径。将此代码添加到 settings.json 文件并保存后,Pylance 应该能够正确检测到您的 Python 安装。

最后,您应该再次安装 pyFirmata,错误应该已解决。

英文:

Assuming that you have installed pyFirmata successfully using the command
pip install pyFirmata, it seems that you may have encountered a misconfiguration issue with the Pylance extension in Visual Studio Code related to the Python path.

To resolve this issue, you can set the correct path by opening the command palette in Visual Studio Code using the shortcut <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd>. Next, type in settings.json and select it from the search results. This will open the settings.json file where you can add the following code snippet:

{
    &quot;python.defaultInterpreterPath&quot;: &quot;C:/Users/Maisu/AppData/Local/Programs/Python/Python311/python.exe&quot;
}

Make sure to replace the path in the code snippet with the correct path where your Python interpreter is installed. After adding this code to the settings.json file and saving it, Pylance should be able to detect your Python installation correctly.

Finally, you should install pyFirmata again, and the error should be gone.

huangapple
  • 本文由 发表于 2023年4月17日 16:33:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76033158.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定