Home ยป Associate Thonny with a Virtual Environment on Raspberry Pi

Associate Thonny with a Virtual Environment on Raspberry Pi

  • by
virtual environments in thonny on raspberry pi
Want to do a random act of kindness? Share this post.

In this small blog post I explain how you can work with a virtual environment in Thonny on a Raspberry Pi. But first, let’s create a virtual environment using venv.

  • Open the terminal
  • Change directory to the folder of your project (cd), or create a new one (mkdir)
  • Inside that folder, create the virtual environment using python3 -m venv ./env

You can activate the virtual environment inside your terminal using the command source ./env/bin/activate. However, if you would like to associate Thonny, the default Python editor on Raspbian, with your virtual environment, these are the steps you should take.

Open Thonny, and make sure you switch to Regular Mode. This will allow you to access the menu.

Open Tools > Options and select the Interpreter tab. In the combo box, select an Alternative Python 3 interpreter or virtual environment.

Browse yo the folder of your virtual environment. Inside the bin folder, you should be able to find the python3 executable. Select it, close the menu. Now Thonny will restart the shell and start Python from inside the virtual environment.

Great success!

Want to do a random act of kindness? Share this post.