How to create a python virtual environment for a project in Linux

Python interpreters can be installed globally system-wide or as a virtual environment within a project folder. The advantage of within a virtual environment is isolation of the packages from system-wide use and execution. To set up a virtual environment for a project, open a terminal window and enter the following commands:

$ sudo apt-get install pipenv <enter>

Set up project folder

$ mkdir ~/myproject <enter>
$ cd ~/myproject <enter>
$ mkdir tutorial <enter>
$ cd tutorial <enter>

# Now install the virtual environment into the tutorial folder:
$ pipenv shell <enter>

Once the above is done, then install the Python packages required for the project.

$ pipenv install kivy <enter>

This installs kivy and it’s dependent packages in the virtual environment in the tutorial folder.

Leave a comment