#VSCode – Installing Visual Studio Code @code in a #RaspberryPi, run as root, fix black screen (Updated)

Buy Me A Coffee

Hi!

Now that I have my amazing Raspberry Pi 4 with 4GB RAM, it’s time to see how serious the device is. So, I decided to install and use some developers’ tools in the RPi. My dev list will be something like this

  • Python
  • Some ML and AI Python packages
  • GIT
  • Arduino
  • Visual Studio Code

It’s been a while since I installed VSCode in the device. The last time I did this, I needed to download the code from GitHub and compile the tool in the Raspberry Pi. As far as I remember this was a +25 min process.

Lucky for us the process can now be much simpler, thanks to Headmelted (see references). Now, we only need a single command to install VSCode:

. <( wget -O -
https://code.headmelted.com/installers/apt.sh )

Install process started! Or Maybe not because I found this amazing GPG error

python error installing visual studio code in raspberry pi
pi@rpidev3:~ $ curl -L https://code.headmelted.com/installers/apt.sh | sudo bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2349 0 2349 0 0 19739 0 --:--:-- --:--:-- --:--:-- 19906
Detecting architecture…
Ensuring curl is installed
Reading package lists… Done
Building dependency tree
Reading state information… Done
curl is already the newest version (7.64.0-4).
The following packages were automatically installed and are no longer required:
python3-pyperclip python3-thonny rpi.gpio-common
Use 'apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Architecture detected as armv7l…
Retrieving GPG key headmelted
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
gpg: no valid OpenPGP data found.
Removing any previous entry to headmelted repository
Installing [headmelted] repository…
Updating APT cache…
Hit:1 http://raspbian.raspberrypi.org/raspbian buster InRelease
Hit:2 http://archive.raspberrypi.org/debian buster InRelease
Get:3 https://packagecloud.io/headmelted/codebuilds/debian stretch InRelease [23.4 kB]
Err:3 https://packagecloud.io/headmelted/codebuilds/debian stretch InRelease
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0CC3FD642696BFC8
Reading package lists…
W: GPG error: https://packagecloud.io/headmelted/codebuilds/debian stretch InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0CC3FD642696BFC8
E: The repository 'https://packagecloud.io/headmelted/codebuilds/debian stretch InRelease' is not signed.
Done!
Repository install complete.
Installing Visual Studio Code from [stretch]…
Reading package lists… Done
E: The value 'stretch' is invalid for APT::Default-Release as such a release is not available in the sources
Visual Studio Code install failed.

There a public GPG key used to verify the package and the SH script somehow does not download it (I think the ARM RPI version is still not defined). So, before the previous command, I need to run this command

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

Then run this command

curl -L https://code.headmelted.com/installers/apt.sh | sudo bash

Now we have Visual Studio Code installed!

raspberry pi visual studio code installed

But, yes another but, you may note that the tool open and display a black window. Again, I need to go deeper on the details, but the latest version does not work well. There is some context information on GitHub (see references), and the proposed solution is to rollback to a previous version

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

And we also need to disable the automatic updates on this tool

sudo apt-mark hold code-oss

The following command will remove the hold for Visual Studio Code

sudo apt-mark unhold code-oss

And now, yes, we got a fully functional Visual Studio Code in our Raspberry Pi!

Another update, is a command to run VSCode as root

# open VSCode in default source code folder with root
sudo code-oss --user-data-dir=/home/pi/src/vsCodeUsrData

Of course this is not the best way to use VSCode, however something it helps 😀

Note: Due some Deep Neural Network and docker process, my device is starting to heat a lot, so I’ll try a next generation cooler like this one: Blink Blink ICE Tower CPU Cooling Fan for Raspberry Pi (Support Pi 4)

Happy Coding!

Greetings @ Toronto

El Bruno

References

My posts on El Bruno

#VSCode – Let’s do some #Git dev in #RaspberryPi (GitHub and Azure DevOps!)

Buy Me A Coffee

Hi!

In my previous posts I wrote about how to prepare a developer station with a Raspverry Pi 4. I wrote on how to install Visual Studio Code, how to install .Net Core and how to build and run C# projects. Of course, the next step is to work with Git.

The command to install git is

sudo
apt-get install git

However, I already have Git installed. I haven’t checked, but it seems to me that the latest Raspbian distro includes by default git. I was hoping that VSCode will recognize and use this, but in order to work with Git in VSCode I need some extra work in the IDE settings.

raspberry pi git installed but not integrated in visual studio code

I was able to clone some repositories from GitHub and Azure DevOps, directly from bach

raspberry pi 4 git clone azure devops repository

So, let’s fix Visual Studio Code and Git integration. This one is very easy, I just need to go to Settings, search for Git and define the Git path for VSCode.

raspberry pi 4 visual studio code preferences git

In order to find the git path, we need to use the [which] command

pi@rpidev3:~ $ which git

/usr/bin/git

My got location is [/usr/bin/git].

I’m not a command line dude! I like User Interfaces, so now it’s time to open one of the cloned repositories in Visual Studio Code. I can see that VSCode recognices Git and I can start to commit my files.

raspberry pi 4 visual studio code using git

This is also a perfect moment to define Git user name and user email.

git config --global user.email "email@email.com" 
git config --global user.name "your name"

I like to do this in the Terminal in VSCode, just to check all is working fine.

Happy Coding!

Greetings @ Burlington

El Bruno

References

#VSCode – Build and Run C# #DotNetCore projects in #RaspberryPi

Hi!

Time to move on with some lessons learned using Visual Studio Code in the Raspberry Pi 4.

One of the first issues you may find working with VSCode in the device is related to file write permissions when you are saving a file.

I raspberry pi 4 visual studio code failed to save file

So, it was a good opportunity for me to learn about files and folder permissions in Linux. I found a great starting article “How to Manage File and Folder Permissions in Linux” (see references), and it allowed me to fix this issue.

My next error was triggered when I try to build my project. Again, it was a permission related error.

/home/pi/dotnet/sdk/2.2.401/Microsoft.Common.CurrentVersion.targets(4195,5):
error MSB3021: Unable to copy file "obj/Debug/netcoreapp2.2/dotnethelloworld.dll"
to "bin/Debug/netcoreapp2.2/dotnethelloworld.dll". Access to the path
is denied. [/home/pi/dotnethelloworld/dotnethelloworld.csproj]

However, this time the fix was not related to file and folder permissions.

One of the solutions I found, was to run VSCode with admin privileges. This is probably one of the worst ideas ever, and you can find tons of articles explaining why this is bad (see references).

Anyways, I decided to give it a try. Of course, it worked. Let me share how.

I run VSCode with the following command, which runs the app in root mode.

sudo
code-oss --user-data-dir=/home/pi/dotnethelloworld
raspberry pi 4 visual studio code run as root

The VSCode team is aware of this, so you will find a warning about this scenario

raspberry pi 4 visual studio code run as root warning

Even so, you can still use VSCode to edit and build C# .Net Core Projects.

raspberry pi 4 visual studio code build code

And you can run them also

raspberry pi 4 visual studio code build and run edited code

So far, so good. Or maybe not, broken a lot of good practices. I’ll see this as an amazing chance to learn and test new stuff!

Happy coding.

Greetings @ Burlington

El Bruno

References

#VSCode – Installing Visual Studio Code in a #RaspberryPi, a couple of lessons learned – @code

Hi!

Now that I have my amazing Raspberry Pi 4 with 4GB RAM, it’s time to see how serious the device is. So, I decided to install and use some developers’ tools in the RPi. My dev list will be something like this

  • Python
  • Some ML and AI Python packages
  • GIT
  • Arduino
  • Visual Studio Code

It’s been a while since I installed VSCode in the device. The last time I did this, I needed to download the code from GitHub and compile the tool in the Raspberry Pi. As far as I remember this was a +25 min process.

Lucky for us the process can now be much simpler, thanks to Headmelted (see references). Now, we only need a single command to install VSCode:

. <( wget -O -
https://code.headmelted.com/installers/apt.sh )

Install process started! Or Maybe not because I found this amazing GPG error

python error installing visual studio code in raspberry pi
pi@rpidev3:~ $ curl -L https://code.headmelted.com/installers/apt.sh | sudo bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2349 0 2349 0 0 19739 0 --:--:-- --:--:-- --:--:-- 19906
Detecting architecture…
Ensuring curl is installed
Reading package lists… Done
Building dependency tree
Reading state information… Done
curl is already the newest version (7.64.0-4).
The following packages were automatically installed and are no longer required:
python3-pyperclip python3-thonny rpi.gpio-common
Use 'apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Architecture detected as armv7l…
Retrieving GPG key headmelted
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
gpg: no valid OpenPGP data found.
Removing any previous entry to headmelted repository
Installing [headmelted] repository…
Updating APT cache…
Hit:1 http://raspbian.raspberrypi.org/raspbian buster InRelease
Hit:2 http://archive.raspberrypi.org/debian buster InRelease
Get:3 https://packagecloud.io/headmelted/codebuilds/debian stretch InRelease [23.4 kB]
Err:3 https://packagecloud.io/headmelted/codebuilds/debian stretch InRelease
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0CC3FD642696BFC8
Reading package lists…
W: GPG error: https://packagecloud.io/headmelted/codebuilds/debian stretch InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0CC3FD642696BFC8
E: The repository 'https://packagecloud.io/headmelted/codebuilds/debian stretch InRelease' is not signed.
Done!
Repository install complete.
Installing Visual Studio Code from [stretch]…
Reading package lists… Done
E: The value 'stretch' is invalid for APT::Default-Release as such a release is not available in the sources
Visual Studio Code install failed.

There a public GPG key used to verify the package and the SH script somehow does not download it (I think the ARM RPI version is still not defined). So, before the previous command, I need to run this command

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

Then run this command

curl -L https://code.headmelted.com/installers/apt.sh | sudo bash

Now we have Visual Studio Code installed!

raspberry pi visual studio code installed

But, yes another but, you may note that the tool open and display a black window. Again, I need to go deeper on the details, but the latest version does not work well. There is some context information on GitHub (see references), and the proposed solution is to rollback to a previous version

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

And we also need to disable the automatic updates on this tool

sudo apt-mark hold code-oss

And now, yes, we got a fully functional Visual Studio Code in our Raspberry Pi!

Happy Coding!

Greetings @ Toronto

El Bruno

References

#VSCode- Add #AzureIoT source files to your C++ settings in #VisualStudioCode

Hi!

Context: You may call me picky, but I like to read source code. And if I know that I have the source code, but I can reach it, I can’t code in happy mode.

So, I’m back to Azure IoT and while I was browsing the Project Catalog for my DevKit device. I hold myself in the [Get Started – Connect IoT DevKit AZ3166 to Azure IoT Hub] section thanks to this warning.

visual studio code mxchip get started cant find include errors

Don’t get me wrong, once you installed Visual Studio Code, Arduino and the complete set of dependencies; you can build and deploy everything. However, I need my peek definition and the following error is a stopper for me

visual studio code include file not found in browse.path
Error: Visual studio code include file not found in browse.path 

The main problem is that the C++ extension can’t found any of the Azure IoT files. So, we need to add the path to VSCode settings. Lucky for us, the tip bulb will directly guide us to this option

visual studio code edit browse path setting

We only need to add this path to the C++ settings. Of course, check your Arduino version and your username

C:\Users\{user name}\AppData\Local\Arduino15\packages\AZ3166\**

And that’s it! Peek definition and more is available now

visual studio code c++ peek definition

Happy coding!

Greetings @ Burlington

El Bruno

Resources

#VSCode – Let’s do some #FaceRecognition with 20 lines in #Python (6/N)

Hi !

I’ll start with my posts

  1. Detecting Faces with 20 lines in Python
  2. Face Recognition with 20 lines in Python
  3. Detecting Facial Features with 20 lines in Python
  4. Facial Features and Face Recognition with 20 lines in Python
  5. Performance improvements with code

In my last post I share some lines of code which allowed me to run some of the face recognition demos 6 times faster. I added a Frames per Second (FPS) feature in my samples. Later, thinking about performance, I realize that I don’t need to work with a full HD picture (1920 x 1080), so I added some code to resize the photo before the face detection process.

However, while I was coding arond this solution I also realized that I may want to initialize my camera to start in a lower resolution. So, I searched online on how to do this with OpenCV and I found 3 beautiful lines of code.

open camera with opencv with lower resolution

So, I manage to improve my processing code from 20FPS to +30FPS … which is very good ! Later on this posts I’ll try to do some similar FPS tests on a smaller device and I’ll see and share how this works.

Happy Coding!

Greetings @ Burlington

El Bruno

Resources

#Python – The best way to explain how jupyter notebooks works with Visual Studio Code @Code

Hi !

So, after my yesterday post [Edit and work with Jupyter notebooks in Visual Studio Code], today some people asked me how the Jupyter Notebooks and Python integration works.

The best way to explain this is with a simple animated video with the following actions

  • Create a cell using the prefix # %%
  • Run the cell and display the output in Python Interactive
  • Create a new cell
  • Run the new cell and the previous one
  • Analyze output in Python Interactive

I think this 15 seconds are good enough to understand the benefits of Jupyter Notebooks and Visual Studio Code.

Happy Coding!

Greetings @ NY

El Bruno

References

#VSCode – Edit and work with #jupyter notebooks in Visual Studio Code

Hi !

I’ve been using Python and Jupyter notebooks more and more. And somehow, during this learning path I also realize that I can use Visual Studio Code to code amazing Python apps, and also to edit and work with Jupyter notebooks.

If you are VSCode python developer, you may know some of the features available in the tool. I won’t describe them, because you may find the official documentation very useful (see below links or references).

The Python extension provides many features for editing Python source code in Visual Studio Code:

However, during the part months I’ve also working a lot using Jupyter notebooks, and I was very happy when I realize that VSCode also have some cool features to work with notebooks. The core of the notebooks are cells, and we can use them with the prefix #%%.

This is how it looks inside the IDE, running a cell in the code

Another interesting feature is to run notebooks in a remote Jupyter server, maybe using Azure Notebooks. I haven’t tried this one, and it’s on my ToDo list for the near future.

On top of adding cells features into standard python [.py] files, we can also edit standard Jupyter files. I’ve installed jupyter into one of my anaconda local environments, and now I can edit files inside VSCode.

First, I’ll be prompted to import the file as a standard python file

And, done! Now I got my Jupiter notebook inside VSCode

The final step will be to export my file or debug session, and for this we have the command [Python: Export …]

Super useful!

Happy coding!

Greetings @ NY

El Bruno

References

#VSCode – Visual Studio Code Tools for #AI available at Visual Studio Marketplace @code

Hi!

Happy Thanksgiving! Today is one of those new holidays that I need to learn, now that we are all living in the North. Just as I have to get used to spending more and more time in Visual Studio Code. It’s just because for simple tasks in Python, the experience with this IDE is great.

Well, a few days ago I realized that we also have [Visual Studio Tools for AI] in a specific version for VSCode.

Visual Studio MarketPlace: Visual Studio Code Tools for AI

As always, installation is a very simple process

01 vscode tools for ai install02 vscode tools for ai installed

Once the extension is installed, you may want to spend some time to review that all requirements of the development environment are correctly installed. Mostly focus on drivers and Paths, IMHO they can give you some very not happy times.

This is why it’s worthwhile to spend some time following this links

From here I think I will encourage my first real steps with Deep Learning!

Happy coding!

Greetings @ Burlington

El Bruno

References

Quickstarts

 

#VSCode – Visual Studio Code Tools for #AI disponible en el Visual Studio Marketplace @code

Buenas!

Feliz día de acción de gracias! Hoy es uno de esos festivos nuevos a los que tengo que acostumbrarme en el Norte. Así como tengo que acostumbrarme a pasar bastante tiempo en VSCode. Es solo porque para tareas simples en Python, la experiencia con este IDE es genial.

Pues bien, hoy me he enterado de que [Visual Studio Tools for AI] también tiene su version para VSCode.

Visual Studio MarketPlace: Visual Studio Code Tools for AI

Como siempre la instalación es un proceso muy simple

01 vscode tools for ai install02 vscode tools for ai installed

Una vez instalada la extensión, es conveniente repasar que todos los requerimientos del entorno de desarrollo estén instalados y bien configurados (drivers y paths pueden darte mas de un dolor de cabeza). Es por esto que dedicar un par de minutos a los siguientes links vale la pena

A partir de aquí creo que me animare con mis primeros pasos reales en Deep Learning!

Happy coding!

Saludos @ Burlington

El Bruno

References

Quickstarts