# My Python Environment Cheat Sheet

# Install pyenv

## Mac

```bash
brew update
brew install pyenv

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
```

## Linux

```bash
curl -fsSL https://pyenv.run | bash

sudo dnf builddep python3

export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init - bash)"
```

Add below to .bash\_rc to enable venv

```bash
eval "$(pyenv virtualenv-init -)"
```

# Commands

## pyenv

```bash
# List available versions
# https://www.python.org/doc/versions/
pyenv install -l

# Install a python version
pyenv install 3.12.10

# List currently installed python version
pyenv versions

# Set global python version
pyenv global 3.12.10

# Set python version for a directory
# cd into a directory 
pyenv local 3.12.10

# Set current shell python
pyenv shell 3.12.10

# Remove installation
pyenv uninstall 3.10.10

# Check you current python version
python --version
```

## venv

```bash
mkdir some_dir; cd some_dir
python -m venv .venv
source .venv/bin/activate
```

# Reference

[https://github.com/pyenv/pyenv](https://github.com/pyenv/pyenv)

[https://opensource.com/article/19/5/python-3-default-mac](https://opensource.com/article/19/5/python-3-default-mac)

[https://github.com/pyenv/pyenv](https://github.com/pyenv/pyenv)

[https://dev.to/veer66/pyenv-and-pipenv-on-fedora-13m2](https://dev.to/veer66/pyenv-and-pipenv-on-fedora-13m2)
