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 )
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
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
As we can see in the following screenshot, the virtual environment uses the latest Python 3 version, and just a few packages installed.
More posts in my blog ElBruno.com.
- 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