Code Monkey home page Code Monkey logo

Comments (10)

paulober avatar paulober commented on August 20, 2024 2

@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.

from micropico.

jimkr avatar jimkr commented on August 20, 2024 1

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:

  1. Create an empty folder
  2. In Visual Studio Code, select File | Open Folder, and select the newly created folder
  3. Run MicroPython: Configure Project
  4. Create a main.py 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.

from micropico.

sandylnur avatar sandylnur commented on August 20, 2024 1

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<user-name>l.micropico-stubs\included".

from micropico.

AleksanderKruecken avatar AleksanderKruecken commented on August 20, 2024 1

Does this also happen if you open a blank folder, run configure project and then create a main.py with import machine?

Yes

from micropico.

paulober avatar paulober commented on August 20, 2024

Does this also happen if you open a blank folder, run configure project and then create a main.py with import machine?

from micropico.

HLammers avatar HLammers commented on August 20, 2024

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.

from micropico.

HLammers avatar HLammers commented on August 20, 2024

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.

from micropico.

jimkr avatar jimkr commented on August 20, 2024

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.

from micropico.

HLammers avatar HLammers commented on August 20, 2024

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.

from micropico.

whatdoido4 avatar whatdoido4 commented on August 20, 2024

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

from micropico.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.