> For the complete documentation index, see [llms.txt](https://lauradang.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lauradang.gitbook.io/notes/shell/linux/virtual-environment.md).

# Virtual Environment

## Make virtual environment

```bash
$ pip install virtualenv
$ virtualenv mypython
```

## Start virtual environment

```bash
$ source mypython/bin/activate
```

## Deactivate virtual environment

```bash
$ deactivate
```

## Start virtual environment in Python3

```bash
$ virtualenv -p python3 <envname>
```

## Environment variables inside virtual environment

```bash
$ vi .env
>> Type your environment variables in this file (VAR=VALUE)

$ pip install python-dotenv
```

## Switch python version in virtualenv

**Use case:** Some dependencies are not supported by Python3.8 yet.

```bash
$ virtualenv --python=/usr/bin/python<version> <path/to/new/virtualenv/>

# To find path for python (it's not always /usr/bin/...):
$ which python<version_number>
```
