> For the complete documentation index, see [llms.txt](https://docs.daitya.info/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.daitya.info/dev/multiple-python-on-macos.md).

# Multiple Python versions

## Install Homebrew

Homebrew is a package manager for MacOS, must have CLI utility.

```
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```

## Install latest python

MacOS comes with a python version but you should install the latest stable version of python.

```
 brew install python
```

## Install pip

Download the `get-pip` file

```
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
```

Now run this file to install pip

```
python get-pip.py
```

## Change global default python to latest python

```
sudo ln -s -f /usr/local/bin/python3.9 /usr/local/bin/python
```

## Install pyenv

`pyenv` makes it easy to install, manage, and switch between multiple Pythons versions.

```
brew install pyenv
```

## Install multiple python versions in pyenv

```
pyenv install 3.9.4
pyenv install 2.7.16
```

## Change default python in pyenv to latest and greatest

```
pyenv global 3.9.4
```

## Running pyenv

```
pyenv versions
python -m venv venv
source ./venv/bin/activate
(venv) $ which python
```

To exit the virtual environment

```
deactivate
```

#### References

* <https://opensource.com/article/19/6/python-virtual-environments-mac>
* [https://jacobian.org/2019/nov/11/python-environment-2020/ ](<https://jacobian.org/2019/nov/11/python-environment-2020/ >)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.daitya.info/dev/multiple-python-on-macos.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
