Python Virtual Environment

Python Virtual Environment

This tutorials will explain how to create, activate and deactivate virtual environment in python. Virtual environment is highly recommended for each project to keep dependent libraries separate for development from other projects.

Create virtual environment: Below command will create virtual environment folder with pass venv name(e.g sample_venv_name in this case) in the current working directory.

python3 -m venv sample_venv_name

Activate virtual environment: Source command with a path to activate file can be used to activate virtual environment. Unix Command `pwd` can be used to get current working directory in mac.

source /path-to-virtual-env-folder/sample_venv_name/bin/activate

Deactivate virtual environment: deactivate command can be used to exit virtual environment.