How to configure Micropy-CLI for the Pico.


The easiest way to get started with a new project is to use the Pico-Go > Configure project option within the command palette. However, if you’re more familiar with Micopy-CLI and would prefer to use this, here’s how to use it with Pico-Go.

The Very Basics

You’ll need a few things installed:

  • Python — download and install for your platform;
  • NodeJS — download and install the LTS version for your platform;
  • Visual Studo Code — obviously!

Once you’ve got Python installed, you’ll also want to install Pip. Download this file and then issue the following command from a terminal / Command Prompt window:

# On Linux or macOS  
python get-pip.py
# On Windows  
py get-pip.py

Keep a lookout for any warnings about Pip not being within your PATH environment variable. If you see such a warning, copy the path it mentions and add it into your PATH.

Also, if you’re on a Mac, launch VS Code and from the Command Palette (Command + Shift + P), choose to install the “code” command in PATH:

Other Prerequisites

Right, time to install some stuff specific to our goal: writing code in MicroPython for your Pico board!

pip install micropy-cli  
pip install pylint

The Micropy CLI is used to quickly setup new projects so that they include code completion and linting (i.e. trying to detect problems and errors).

Pylint is what will actually do that linting!

Configuring Micropy CLI

In order to do our code completion and linting, Micropy CLI needs to know a little bit more about the Pico and what it can do. Specifically, it needs to know which Python modules are baked into the board for our use and which functions and properties are included in each.

This is where the Pico-Stub project comes in.

“Stubs” are what provide Micropy (and Pylint) with that intelligence. They’re generated automatically by running Python code on the Pico board itself. They’re then brought back to a normal computer and are made available for use within Micropy CLI through my repo.

Download a copy of the repo and extract the zip file. Then add the stubs to Micropy CLI:

cd Pico-Stub-main/dist  
micropy stubs add micropy-cli

Other VS Code Extensions

Inside VS Code, search for and install the following two extensions:

  • ms-python.python
  • VisualStudioExptTeam.vscodeintellicode

If you haven’t already, install Pico-Go.

Starting a new project

Open up VS Code and, in the terminal, type:

micropy init

It will suggest a project name — just choose the default:

Then you’ll need to choose at least these two options:

If you intend to put your project in a Git repository afterwards, you’ll probably want the Git Ignore Template too.

Finally, you’ll need to choose the Pico’s stubs:

Don’t worry if the numbers look slightly different for you; this just means you’re on a different version of the Pico firmware.

All being well, you should see something like this: