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

Associate Thonny with a Virtual Environment on Raspberry Pi

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!

Say thanks, ask questions or give feedback

Technologies get updated, syntax changes and honestly… I make mistakes too. If something is incorrect, incomplete or doesn’t work, let me know in the comments below and help thousands of visitors.

4 thoughts on “Associate Thonny with a Virtual Environment on Raspberry Pi”

Leave a Reply

Your email address will not be published. Required fields are marked *