When installing Python packages with pip, you may find warning messages about some dependency packages versions not being compatible with other installed packages. You can create isolated containers (virtual environments) in which you can safely install any Python package.

Table of Contents

Install virtualenv

To create virtual environments, first you need to install virtualenv using pip.

pip install virtualenv
# or
python -m pip install virtualenv

Create a virtual environment

The process of creating a virtual environment will create a folder inside your working directory. You can name the environment whatever you want. The resulting folder will have that name.

virtualenv <name>

Activate the environment

Finally, to “enter” into the virtual environment, execute the file named activate inside <name>/bin/. You can use source to do this.

source ./<name>/bin/activate

Your terminal prompt will display the environment name inside parenthesis:

(ocrmypdf) [ricardo@myarch python-environments]$

You’re now inside an isolated container where you can install python packages without worrying about dependency conflicts.

(dooit) [ricardo@myarch dooit]$ python -m pip install git+https://github.com/kraanzu/dooit.git
Collecting git+https://github.com/kraanzu/dooit.git
  Cloning https://github.com/kraanzu/dooit.git to /tmp/pip-req-build-va8pmhkt
  Running command git clone --filter=blob:none --quiet https://github.com/kraanzu/dooit.git /tmp/pip-req-build-va8pmhkt

Exit from the virtual environment (deactivate)

Just run deactivate and you’ll notice the default terminal prompt will go back (without the environment name inside parenthesis).