Setting up Python Dev Environment
Developing multiple python projects in local machine may require different python environments to run.
Example: Python 3.12 has the telnetlib library bundled in the standard library. In Python 3.13, it’s removed. Code relying on it works in 3.12 but fails in 3.13.
Without python version management, this sort of breakage can waste hours in debugging.
This post shows one way of setting up development environment so that the machine have the flexibility to handle different python projects that may require different python environments:
- pyenv → manage multiple Python versions
- pipx → install CLI tools in isolated environments
- poetry → handle dependencies + virtual environments per project
Prerequisites
- macOS, Linux, or WSL (Windows users can start with WSL2 + Ubuntu)
gitcurl(orbrewon macOS)
Step 1: Install pyenv
curl https://pyenv.run | bash
⚠️ Add the init script to your shell config (~/.zshrc or ~/.bashrc):
bashrc
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init - bash)"' >> ~/.bashrc
zshrc
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init - zsh)"' >> ~/.zshrc
Reload your shell:
exec $SHELL
Step 2: Install Multiple Python Versions
pyenv install 3.12.11
pyenv install 3.13.7
pyenv versions
Switch per-project:
pyenv local 3.12.11
python --version # Should print 3.12.11
Step 3: Install pipx for CLI Tools
pip install --user pipx
pipx ensurepath
Nice benefit: pipx keeps tools like poetry isolated, so they won’t clash between projects.
Step 4: Install poetry
pipx install poetry
Example: Demonstrating Python Version Differences
Refer to demo repository: aikmeng/demo-poetry-env.
Python 3.13 removed telnetlib, which causes imports to fail if upgrading blindly.
pyenv, pipx, and poetry together make version pinning and isolated tooling straightforward.