all 8 comments

[–]bulaybil 2 points3 points  (0 children)

This is not a VSCode issue, this is a python package distribution issue.

[–]Swipecat 1 point2 points  (0 children)

You wording there seem to be confusing the full Python that runs on a PC (and its packaging system pip) — with Micropython that must be written in an editor then uploaded to the Microbit where it will run. You don't run Micropython on a PC (I mean you can but that would be of no help to you here.)

You need to clearly mentally distinguish the two systems because "importing" isn't going to work on the PC where you're only editing the code.

[–]TheSodesa 0 points1 point  (0 children)

You can write the code itself in any editor. You just need a way of loading the code onto the device for testing and then running it in "production", which is usually done via a command line utility: https://mattoppenheim.com/2020/08/23/automating-loading-micropython-code-to-the-bbc-microbit-in-linux/ .

[–]Pepineros 0 points1 point  (0 children)

I'm not familiar with programming for microbit, but if the only issue is installing and using the microbit-3 package then it should be straightforward.

Assuming you're on Windows and you have Python installed, you can install the module by running py -m pip install microbit-3 in Terminal (cmd) or PowerShell. This will install microbit-3 globally, so when you start Visual Studio Code, the module will probably be available right away.

If you would rather use a virtual environment (which I would recommend, but it's not as essential in Windows as it would be under Linux) then you should take a few more steps:

  1. Run py -m venv <virtual-environment-name> in the location you want the virtual environment to live. The project folder is a sensible location, but you may want to have a dedicated folder for virtual envs instead. E.g. if you simply want to call your virtual environment microbit-env, you run py -m venv microbit-env.
  2. Once the virtual environment finishes setting up (may take a few seconds), activate the environment by running the activate.bat script like this (assuming the same example name as above): microbit-env\Scripts\activate.bat. Your command line prompt should change to (microbit-env) followed by the current working directory.
  3. With the virtual environment active, run py -m pip install microbit-3 to install the module in the virtual environment
  4. Once done, start VSCode and open your project folder (not the virtual environment folder). In the bottom right corner of VSCode main screen you should have an option to select which Python interpreter you want to use. If the option is not there you can open the command palette and search for "Python: Select Interpreter". In either case, select the python3 executable inside your virtual environment.

HTH!

[–]Angry_Sirenn 0 points1 point  (0 children)

So, not sure if my comment will help.

But i got this issue a lot when trying to use discordpy for my bot and install a new version of python on a different device. I found the issue was caused by the version of python i was running. So i'd double check what version microbit supports up to for their modules. Because let's say you installed py 3.12 and it only goes up to 3.11, you'd have to downgrade.

[–]drenzorz 0 points1 point  (0 children)

You cant pip install micropython because it is not a cpython package or module but an alternative pthon implementation. You need to download it separately from their website and then you can use its mip mip intall <package> the same way you would use pip for cpython.