1.3. Virtual Environments#

By default, PIP install packages in a global site_packages folder. By consequence, Python packaging has one big problem: You can’t install multiple version of a package concurrently on your computer.
Managing the dependencies of multiple Python projects is non-trivial.

Fortunately, we can use virtual environments to handle dependencies of different Python projects.

In nutshell, virtual environment prepends a folder to the system $PATH, which contains its local site_packages. When installing packages with a virtual environment, the packages will therefore be installed within that local folder only.

Best Practice: use a different virtual environment for each projects to avoid conflict of dependencies between projects.

1.3.1. venv#

Python offers a built-in module called venv to manage virtual environments.

To create a new virtual environment run:

$ python -m venv [virtual-env]

To activate a virtual environment:

$ source /path/to/venv/bin/activate

Note: on Windows use \path\to\venv\Scripts\activate.bat

To deactivate the current virtual environment:

$ deactivate

1.3.2. Conda#

Conda or Miniconda is an alternative to venv that focuses on data science packages. It offers a packaging solution for multiple types of binaries, including Python.

Anaconda wrote a concise comparison between PIP and Conda packaging in their documentation.

Download the latest available version of Miniconda for your system from the Miniconda archive.

1.3.2.1. OSX & Linux#

Execute the shell script:

$ sh miniconda.sh

1.3.2.2. Windows#

Execute the command:

> start /wait "" Miniconda3-latest-Windows-x86_64.exe /InstallationType=JustMe /RegisterPython=0 /S /D=%UserProfile%\Miniconda3

Refer to the Conda installation documentation for complete steps to install and configure.