7.6. Environment Management

7.6.1. virtualenv-clone: Create a Copy of a Virtual Environment

Sometimes you might want to use the same virtual environment for 2 different directories. If you want to create a copy of a virtual environment, use virtualenv-clone.

The code below shows how to use virtualenv-clone.

$ pip install virtualenv-clone
$ virtualenv-clone old_venv/ new_venv/

$ source new_venv/bin/activate

Link to virtualenv-clone.

7.6.2. pip-autoremove: Remove a Package and Its Unused Dependencies

When using pip uninstall, you only remove a specific package.

!pip install -U pandas-profiling[notebook]
$ pip uninstall pandas-profiling[notebook] -y
!pip uninstall pandas-profiling[notebook] -y
Found existing installation: pandas-profiling 3.1.0
Uninstalling pandas-profiling-3.1.0:
  Successfully uninstalled pandas-profiling-3.1.0

Wouldn’t it be nice if you can uninstall that package and its unused dependencies? That is when pip-autoremove comes in handy.

!pip install pip-autoremove
Collecting pip-autoremove
  Downloading pip_autoremove-0.10.0-py2.py3-none-any.whl (5.0 kB)
Requirement already satisfied: setuptools in /home/khuyen/book/venv/lib/python3.8/site-packages (from pip-autoremove) (44.0.0)
Requirement already satisfied: pip in /home/khuyen/book/venv/lib/python3.8/site-packages (from pip-autoremove) (21.2.4)
Installing collected packages: pip-autoremove
Successfully installed pip-autoremove-0.10.0
!pip install -U pandas-profiling[notebook]
$ pip-autoremove pandas-profiling[notebook] -y
!pip-autoremove pandas-profiling[notebook] -y
Jinja2 3.0.1 is installed but jinja2~=2.11.2 is required
Redoing requirement with just package name...
spacy 3.1.2 is installed but spacy<3.0.0 is required
Redoing requirement with just package name...
markdown-it-py 0.6.2 is installed but markdown-it-py~=1.0 is required
Redoing requirement with just package name...
attrs 21.2.0 is installed but attrs<21,>=19 is required
Redoing requirement with just package name...
typer 0.3.2 is installed but typer[all]>=0.4 is required
Redoing requirement with just package name...
fsspec 0.8.7 is installed but fsspec[http]>=2021.8.1 is required
Redoing requirement with just package name...
pandas-profiling 3.1.0 (/home/khuyen/book/venv/lib/python3.8/site-packages)
    seaborn 0.11.2 (/home/khuyen/book/venv/lib/python3.8/site-packages)
    htmlmin 0.1.12 (/home/khuyen/book/venv/lib/python3.8/site-packages)
    phik 0.12.0 (/home/khuyen/book/venv/lib/python3.8/site-packages)
    multimethod 1.6 (/home/khuyen/book/venv/lib/python3.8/site-packages)
    tangled-up-in-unicode 0.1.0 (/home/khuyen/book/venv/lib/python3.8/site-packages)
    visions 0.7.4 (/home/khuyen/book/venv/lib/python3.8/site-packages)
    missingno 0.5.0 (/home/khuyen/book/venv/lib/python3.8/site-packages)
Found existing installation: phik 0.12.0
Uninstalling phik-0.12.0:
  Successfully uninstalled phik-0.12.0
Found existing installation: multimethod 1.6
Uninstalling multimethod-1.6:
  Successfully uninstalled multimethod-1.6
Found existing installation: pandas-profiling 3.1.0
Uninstalling pandas-profiling-3.1.0:
  Successfully uninstalled pandas-profiling-3.1.0
Found existing installation: seaborn 0.11.2
Uninstalling seaborn-0.11.2:
  Successfully uninstalled seaborn-0.11.2
Found existing installation: tangled-up-in-unicode 0.1.0
Uninstalling tangled-up-in-unicode-0.1.0:
  Successfully uninstalled tangled-up-in-unicode-0.1.0
Found existing installation: visions 0.7.4
Uninstalling visions-0.7.4:
  Successfully uninstalled visions-0.7.4
Found existing installation: htmlmin 0.1.12
Uninstalling htmlmin-0.1.12:
  Successfully uninstalled htmlmin-0.1.12
Found existing installation: missingno 0.5.0
Uninstalling missingno-0.5.0:
  Successfully uninstalled missingno-0.5.0

By using pip-autoremove, pandas-profiling and its unused dependencies are removed!

Link to pip-autoremove.