Skip to content

Instantly share code, notes, and snippets.

@lalalune
Created May 4, 2024 17:27
Show Gist options
  • Save lalalune/986704a935d202ab2350ca90b2fc9755 to your computer and use it in GitHub Desktop.
Save lalalune/986704a935d202ab2350ca90b2fc9755 to your computer and use it in GitHub Desktop.
### Installing Python 3.10 on macOS
1. **Install Homebrew** (if not already installed):
- Open a terminal and install Homebrew by running:
```bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```
- Follow the on-screen instructions to complete the installation.
2. **Install pyenv** using Homebrew:
- Run:
```bash
brew install pyenv
```
3. **Add pyenv to your shell**:
- For Bash, add the following lines to your `~/.bash_profile`:
```bash
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
```
- For Zsh, add the following lines to your `~/.zshrc`:
```bash
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
```
- Restart your terminal or run:
```bash
source ~/.bash_profile # or source ~/.zshrc
```
4. **Install Python 3.10**:
- Check available versions:
```bash
pyenv install --list | grep 3.10
```
- Install Python 3.10.x (replace `x` with the latest patch number found):
```bash
pyenv install 3.10.x
```
5. **Set Python 3.10 as the default version** for your session or globally:
- To set it globally, run:
```bash
pyenv global 3.10.x
```
### Installing Python 3.10 on Linux
1. **Install dependencies** (for Ubuntu/Debian):
- Run:
```bash
sudo apt update
sudo apt install -y build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev python-openssl git
```
2. **Install pyenv**:
- Clone pyenv repository to `~/.pyenv`:
```bash
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
```
- Configure the environment for pyenv (for Bash):
```bash
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init --path)"' >> ~/.bashrc
source ~/.bashrc
```
- For Zsh, modify `.zshrc` instead of `.bashrc`.
3. **Install Python 3.10** and set it as default, following the steps provided above for macOS.
Using `pyenv` allows you to switch between Python versions easily and is especially useful in development environments where multiple Python versions are needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment