# Running multiple versions of Python on your machine using pyenv

I needed to test sending emails with SendGrid using Python, but as per the docs, it needed Python 3.8 be able to do so. At that time, my machine had Python 3.11 installed. So, I needed to switch my Python version for the assignment.

This is when we use **Pyenv**.

Pyenv is available for download easily using Homebrew for Mac and Linux.  
To install, run:

```bash
brew update
brew install pyenv
```

Check all available Python versions available for download using `pyenv`:

```bash
pyenv install --list
```

Install a particular version of Python:

```bash
pyenv install 3.8
```

Set the Python version for your project by running the command below from the project's root directory:

```bash
pyenv local 3.8
```

Check the local version in your current project:

```bash
pyenv local
```

Now create a virtual environment for the selected Python version:

```bash
pyenv exec python -m venv .env
```

Activate the virtual environment:

```bash
source .env/bin/activate
```
