#RaspberryPi – Install Virtual Environments

Buy Me A Coffee

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

My posts on Raspberry Pi ⚑🐲⚑

Dev posts for Raspberry Pi
Tools and Apps for Raspberry Pi
Setup the device
Hardware

Advertisement

1 comment

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: