Whether you’re learning your first steps in programming or you’re an experienced developer, you’ll be learning a lot of code. A good code editor is a must, but the options for the Raspberry Pi are limited.

Visual Studio Code is a free integrated development environment (IDE) for Windows, Mac, and Linux. This is not available for Raspberry Pi. However, since it’s open source, anyone can compile a version.

Below you will learn how to install Code-OSS, a community compiled version of VS Code, on your Raspberry Pi.

Why do I need an IDE?

The Raspbian Stretch Operating System (OS) comes with several code editors already installed. You may be wondering why install another one?

Code-OSS is based on VS Code and is more than just a code editor. Most IDEs have built-in explorers for managing entire project folders rather than individual scripts. Many support code completion and have built-in terminals for code testing. Some also support version control and dependency management for packages.

In short, IDEs make your life easier. Exactly what you choose is a personal preference.

Why install Code-OSS?

All these reasons why IDEs are great? Code-OSS can make them. Because it’s essentially a fully functional version of VS Code under a different name, it probably has the most features of any coding tool currently available on the Pi.

Raspberry Pi is the swiss army knife of minicomputers

This doesn’t mean it’s perfect. The Pi suffers from its success, and older Pi models may experience performance issues when using Code-OSS. This tutorial uses a Raspberry Pi 3B+ that runs the program without any problems.

Why not install VS Code?

Given the fact that Code-OSS is the same as VS Code maintained by Microsoft, why not just install VS Code?

There is currently no official release of VS Code for ARM devices such as the Raspberry Pi. While this may change in the future, Code-OSS is your best bet for now!

How to get an OSS code

Headmelted site image for Linux and Chromebook builds VS Code

Code-OSS created by Jay Rogers is available on his popular GitHub page.

It also maintains a website with installation instructions. To continue, you will need to open both of these sites in a browser along with a terminal window.

Installing a GPG key

Terminal output to add GPG key to install Code-OSS
Installing Code-OSS for Pi currently requires additional steps that are not listed on the website. Scroll down to the Linux section and look under » Manual installation» .

Here you will find a link to GPG public key . Use this key in the terminal with the following command:

wget -o - https://packagecloud.io/headmelted/codebuilds/gpgkey| sudo apt-key add - 

Pay attention to the distance as it needs to be done right! This command downloads the key that is part of the Gnu Privacy Guard (GPG) and adds it to your system. This does not install Code-OSS, it just ensures that when you download the program, it will install correctly.

Installing Code-OSS

Currently, following the instructions on the headmelted website results in a successful installation, but the program does not launch. A fix for this bug may come in time, but for now the answer is to install an earlier version of Code-OSS.

Enter this code in terminal:

 sudo apt-get install code-oss=1.29.0-1539702286 

This version will work, but every time your system is updated, it breaks again. A workaround is available in the release on the Github page for the project. Tagging Code-OSS as retention using the terminal, it will not update automatically.

 apt-mark hold code-oss 

Now it is carried out in the working version. Change it anytime, re running command, replacing hold with unhold .

Introducing Code-OSS

Welcome screen for VS Code, or in this case Code-OSS.

Open Code-OSS from the Raspberry Pi application menu. If you’ve used VS Code before, this should look very familiar. Apart from the name, the program looks and behaves the same.

On the left side is a toolbar for opening folders, searching in projects, version control, debugging, and extensions. Covering all of these features is beyond the scope of this article. For now, let’s install the Python extension.

Click the box logo on the left toolbar to open the extensions menu. Code-OSS shares a vast library of add-ons and helpers with VS Codes for just about every type of code, language, or project imaginable.

Find Python in the menu and click » Install». After installation, you will need to restart Code-OSS.

OSS Code Testing

To test the extension, let’s make a quick Python script to control GPIO pins. Setting up an LED with your Pi for this test is optional and I won’t describe the circuit diagram here. If you’d like to follow our guide to using LEDs with the Pi, will help you set up.

Enter this code and see how Code-OSS will help you with this:

 from gpiozero import LED from time import sleep led = LED(17) #Change this to your LED's GPIO pin number! while True: print("LED on") led.on() sleep(1) print("LED off") led.off() sleep(1) 

The Python extension provides code completion along with real-time code checking. Any errors should be highlighted in real time.

It is working! Something like.

You will probably notice a couple of errors on the bottom right side of the screen.

Python extension errors in Code-OSS

If you are using Pylint, you will be familiar with this error. The usual fix is ​​to install the correct version of pylint for your Python installation. Another error is related to the fact that Python Language Server does not currently support Pi. This isn’t a problem as the default is Jedi instead, which sounds a lot cooler.

If you don’t understand what this means, feel free to ignore it!

All in one place

Installing Code-OSS doesn’t just make code editing easier. Code-OSS has a terminal built right into the program. You can open a terminal by selecting View > Terminal or by clicking Ctrl + ` .

Built-in, full-featured terminal in Code-OSS

Alternatively, you can run any Python script from command palette . Opening it in Code-OSS is the same as in VS Code. Click Ctrl+Shift+P to open the command palette and find Python: run python file in terminal .

Code-OSS command palette that runs Python code in the built-in terminal

Once you select it, the terminal will run your program, all within Code-OSS. Being able to access all your code and terminal in one place is a game changer on the Raspberry Pi!

Big update for Raspberry Pi encoders

This is definitely a significant update. This isn’t to say that the tools already on the Pi aren’t good enough, in fact we used the pre-installed IDLE code editor for our Raspberry Pi LED control guide, and it was just fine.

Although it’s certainly nice to have something more complete. Code-OSS can do a lot more than what can be covered here. Why not spend some time writing code on the Raspberry Pi to deal with Code-OSS?

Похожие записи