Closed HLammers closed 2 months ago
Does this also happen if you open a blank folder, run configure project and then create a main.py with import machine?
I'm encountering similar symptoms with a new project
Does this also happen if you open a blank folder, run configure project and then create a main.py with import machine?
Yes, it does
Steps to reproduce on Windows 10:
MicroPython: Configure Project
main.p
y file with the single line import machine
At this point, I see the error from Pylance: Import "machine" could not be resolved
My .vscode\settings.json
file contains this setting:
"python.analysis.extraPaths": [
"~\\.micropico-stubs\\included"
]
The micropico stubs do exist in my Windows user's home directory in a folder .micropico-stubs\included
As a workaround, I copied the .micropico-stubs directory from my home directory to my project directory. I changed the above lines in .vscode\settings.json
to also reference the project relative copy of the stubs:
"python.analysis.extraPaths": [
"~\\.micropico-stubs\\included",
".micropico-stubs\\included"
]
After saving .vscode\settings.json
, the error resolving import machine
goes away.
It appears that Pylance is not successfully using the stubs in my Windows user home directory.
Does this also happen if you open a blank folder, run configure project and then create a main.py with import machine?
Yes, I can confirm that as well. I haven’t tried @jimkr’s work around yet.
I confirm the issue as well, @jimkr work around worked, instead of copying the whole directory I simply used the absolute path with my user account, for me being "C:\Users\
Does this also happen if you open a blank folder, run configure project and then create a main.py with import machine?
Yes
Following @sandylnur's suggestion to add the absolute path of the users folder to settings.json, partly resolves the problem, but not completely. It recognises machine
, but it doesn't recognise parts of gc
and time
:
import gc
is recognised, so are gc.enable()
and gc.collect()
, but gc.threshold()
, gc.mem_free()
and gc.mem_alloc()
are not.import time
is recognised, but time.sleep_ms()
, time.ticks_ms()
and time.ticks_diff()
are not.it doesn't recognise parts of gc and time
I'd guess that pylance is using the python standard library versions of time and gc, which contain different methods. It's not using the micropython stubs, so isn't aware of the micropython functions.
I'm not sure how (or whether it's even possible) to make the micropython stubs take precedence.
Could it have something to do with the version of MicroPython I'm using (1.23)? I don't think it should, because it used to be working when I was using the 1.23 preview.
@HLammers No, the syntaxhighlighting and auto-completion is completely independent from the firmware installed on your board. The problem could be ~ as prefix for the user home in the vscode configuration. I have to do some test but I may have a solution to this.
Error in Python Language server output with absolute path entered into pylance settings "include" paths and nothing in settings.json:
2024-06-17 14:52:54.371 [info] Auto-Indent enabled 2024-06-17 14:52:54.377 [info] [Info - 2:52:54 PM] (20844) Setting pythonPath for service "Firmware": "C:\Program Files (x86)\Python310-32\python.exe" 2024-06-17 14:52:54.377 [info] [Info - 2:52:54 PM] (20844) Setting environmentName for service "Firmware": "3.10.11 (global)" 2024-06-17 14:52:54.576 [info] [Info - 2:52:54 PM] (20844) Assuming Python version 3.10.11.final.0 2024-06-17 14:52:54.867 [info] [Info - 2:52:54 PM] (20844) Found 143 source files 2024-06-17 14:52:54.908 [info] Auto-Indent enabled 2024-06-17 14:52:54.909 [info] [Info - 2:52:54 PM] (20844) Setting environmentName for service "Pico (W) Remote Workspace": "3.10.11 (global)" 2024-06-17 14:52:55.166 [info] [Error - 2:52:55 PM] (20844) File or directory "pico:c%3A/users/#######/.micropico-stubs/included" does not exist. 2024-06-17 14:52:55.208 [info] [Info - 2:52:55 PM] (20844) No source files found. 2024-06-17 14:52:55.214 [info] Auto-Indent enabled
What are the steps to reproduce this issue?
What happens?
Pylance shows errors when using Micropython specific keywords. For example:
import machine
gives the error ‘Import "machine" could not be resolved Pylance [reportMissingImports]’. The code can be uploaded to a Pico and runs normally.What were you expecting to happen?
I expect those Micropython specific keywords to be recognised normally after reopening the project, just as it used to be.
Any logs, error output, etc?
Any other comments?
Rerunning Micropico: Configure project doesn’t resolve the issue, also not after deleting the .micropico file.
Which version of MicroPico are you using?
3.7.8
Support info
Copy this from the
Help -> Info/About -> Copy
(Code -> About Visual Studio Code -> Copy
on macOS) option in Visual Studio Code: