paint-brush
Set up a Virtual Environment with Virtual Environment Wrapper on Linuxby@kcl
993 reads
993 reads

Set up a Virtual Environment with Virtual Environment Wrapper on Linux

by Khadka's Coding Lounge.August 20th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

The objective of this blog is to help my fellow readers, set up a Virtual Environment Wrapper in Linux OS. To follow along with the blog, you're gonna need pip installed in your system. It is easy to access, create and delete virtual environments using a virtual environment wrapper. The following steps are followed by the instructions for installing the virtual environment wrapper on Linux OS: install virtualenvwrapper and set the settings permanently in the BashRc and bash_profile files. The instructions are required to use pip to set up the wrapper.
featured image - Set up a Virtual Environment with Virtual Environment Wrapper on Linux
Khadka's Coding Lounge. HackerNoon profile picture


Intro

Virtual Environment Wrapper is a management tool for virtual environments. It is easy to access, create and delete virtual environments using a virtual environment wrapper. The objective of this blog is to help my fellow readers, set up a Virtual Environment Wrapper on Linux OS.


Pre-requisite

To follow along with the blog, you're gonna need pip installed in your system. If you haven't, then you can read my blog about creating a virtual environment.


Install Virtual Environment Wrapper

  1. Open command terminal:


 pip install virtualenvwrapper


  1. Make a directory for storing virtual environments


mkdir ~/.virtualenvs


  1. Set the directory as the go-to directory for the wrapper


export WORKON_HOME=~/.virtualenvs


  1. Provide a Virtual Environment Wrapper path to your python installation


VIRTUALENVWRAPPER_PYTHON='/usr/bin/python3'


  1. Provide the path to the wrapper for the start-up shell


source /usr/local/bin/virtualenvwrapper.sh


  1. Create a virtual environment


mkvirtualenv yourEnvName


This command will create as well as activate your environment at once. You'll probably see two environments, your base environment, and the newly created environment.


  1. Deactivate the virtual environment with:


deactivate


  1. Check the list of environments in your wrapper with:


workon


  1. Switch the environments with:


workon envronment_name


workon command not found

Now, when you close the terminal and then restart it, and then type workon, the terminal will not recognize workon command. It's because we have yet to add the settings permanently in .bashrc and .bash_profile files.


  1. On bashrc File

Open the bash file on nano editor.

nano ~/.bashrc


On the bashrc file go to the end of the line (where doesn't matter, it's just to keep it simple) and add the following lines:


#Virtual Env Wrapper settings
export WORKON_HOME=~/.virtualenvs
VIRTUALENVWRAPPER_PYTHON='/usr/bin/python3'
source /usr/local/bin/virtualenvwrapper.sh


Now, Press Ctrl+S to save the file and Ctrl+X to exit.


  1. On bash_profile File

Open the file on nano editor.

nano ~/.bash_profile


Add the following towards the end.

# For Virtual Wrapper
source ~/.local/bin/virtualenvwrapper.sh


Now, Press Ctrl+S to save the file and Ctrl+X to exit.


After this, you're all set. Close and reopen the terminal and type workon, it'll list all the environments in your wrapper.


Thank you for reading. If this article helped you then please give it a like to show support. If you found any error while following the steps please mention it in the comment.



Also published here.