
Hi!
Virtual Environments are a great way to isolate our dev tests, and after been using this in Windows also, work with them in the Raspberry Pi makes a lot of sense.
I’ll leave here the necessary steps to do this, however the full credit is based on some posts from Adrian Rosebrock and his amazing blog (see references).
Once we have everything updated in our Raspbian, let’s run the following command:
sudo pip install virtualenv virtualenvwrapper
sudo rm -rf ~/get-pip.py ~/.cache/pip
Now we need to update the ~/.bashrc file using nano (not a big fan of VI )
nano ~/.bashrc
And then add the following lines
# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh

Now everytime we open a new terminal session, this commands will be applied and we will have our virtual environments up and running.
Next, source the bashrc file
source ~/.bashrc
And we can create a new virtual environment. Let’s create one named devOpenCV using python 3.
mkvirtualenv devOpenCV -p python3
We can enable and access the virtual environment with the workon command, and we will see the virtual environment as a prefix in our terminal
workon devOpenCV
As we can see in the following screenshot, the virtual environment uses the latest Python 3 version, and just a few packages installed.

Happy coding!
Greetings
El Bruno
More posts in my blog ElBruno.com.
More info in https://beacons.ai/elbruno
References
- PyImageSearch, Accessing RPi.GPIO and GPIO Zero with OpenCV + Python
My posts on Raspberry Pi β‘π²β‘
Dev posts for Raspberry Pi
- How to grant permissions to a folder after git clone, to perform dotnet restore on a Raspberry Pi
- How to install .Net Core 3.1 in a Raspberry Pi 4
- Installing Visual Studio Code in a Raspberry Pi 4, run as root, fix black screen
- How to install .Net Core in a Raspberry Pi 4 and test with Hello World
- Build and Run C# NetCore projects in a Raspberry Pi 4 with Visual Studio Code
- Letβs do some Git dev in Raspberry Pi 4 (GitHub and Azure DevOps!)
- Install OpenCV
- Install Python π Virtual Environments in Raspberry Pi
- Setup SSH passwordless access to remote work with Docker π³
- Manage Docker π³ as a non-root user
- Build Docker π³ images from Visual Studio Code remotely using a Raspberry Pi
Tools and Apps for Raspberry Pi
- Where is my Task Manager in RaspberryPi? Letβs try htop
- Multi-monitor πΊ in Raspberry Pi 4 rocks !
- Double Commander on RaspberryPi4, because files are important
- How to install Docker π³ in a Raspberry Pi 4
- Installing Visual Studio Code in a Raspberry Pi
- Installing Visual Studio Code in a Raspberry Pi, run as root, fix black screen (Updated)
- 6 commands to install OpenCV for Python π in a Raspberry Pi 4
Setup the device
- 1st Setup without monitor πΊ: auto connect to WiFi πΆ, enable SSH, update and more
- Setup without monitor: enable VNC
- How to enable auto start with HDMI safe mode
- Running a Python π script in a Python Virtual Environment on reboot / startup
- Setup Wifi on Ubuntu
1 comment