Python Environment Management Workflow
๐ฏ Overview
A hybrid Python development setup that allows seamless switching between modern Python 3.12.3 for personal projects and legacy Python 3.8.13 for school/work projects.
โ๏ธ Core Configuration
๐คฉ Zsh Configuration (~/.zshrc)
# =========================
# ๐ PYENV CONFIGURATION
# =========================
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
# =========================
# ๐ฆ PIPENV CONFIGURATION
# =========================
export PIPENV_VENV_IN_PROJECT=1
๐ง Installed Python Versions
-
System Python: 3.12.3 (Ubuntu default)
-
Pyenv Python 3.12.3: For modern projects (optional but recommended)
-
Pyenv Python 3.8.13: For legacy/school projects
๐ Workflow
๐งช For Modern Projects (Python 3.12.3)
# Create project
mkdir my_modern_project
cd my_modern_project
# Install dependencies (auto-uses Python 3.12.3)
pipenv install flask requests pandas
# Verify Python version
pipenv run python --version # Python 3.12.3
# Activate environment
pipenv shell
๐ซ For Legacy Projects (Python 3.8.13)
# Create project
mkdir school_project
cd school_project
# Install dependencies with explicit Python version
pipenv --python 3.8 install django flask
# Verify Python version
pipenv run python --version # Python 3.8.13
# Activate environment
pipenv shell
๐ Project Structure
~/codeWorld2/
โโโ my_modern_api/ # Python 3.12.3
โ โโ .venv/
โ โโ Pipfile
โ โโ Pipfile.lock
โโโ school_assignment/ # Python 3.8.13
โ โโ .venv/
โ โโ Pipfile
โ โโ Pipfile.lock
โโโ quick_scripts/ # Python 3.12.3
โโ .venv/
โโ Pipfile
โโ Pipfile.lock
๐ ๏ธ Key Commands
๐งฌ Environment Management
# Create new environment
pipenv install package_name
# Activate environment
pipenv shell
# Run commands without activating
pipenv run python script.py
# Deactivate environment
exit
# Remove environment
pipenv --rm
๐คฉ Python Version Management
# List available Python versions
pyenv versions
# Set global Python version
pyenv global 3.12.3
# Set local Python version for project
pyenv local 3.8.13
# Install new Python version
pyenv install 3.8.13
๐ฆ Dependency Management
# Install production dependency
pipenv install requests
# Install development dependency
pipenv install --dev pytest
# Generate requirements.txt
pipenv lock -r > requirements.txt
# Install from existing Pipfile
pipenv install
๐ Workflow Examples
๐ง Starting a New Modern Project
mkdir my_fastapi_app
cd my_fastapi_app
pipenv install fastapi uvicorn
pipenv run python --version # 3.12.3
pipenv shell
# Start coding...
๐ซ Working on School Assignment
mkdir phase3_challenge
cd phase3_challenge
pipenv --python 3.8 install django pandas
pipenv run python --version # 3.8.13
pipenv shell
# Work on assignment...
๐ค Cloning Existing Repository
git clone <project-url>
cd project-name
# Check Pipfile for required Python version
cat Pipfile
# If Python 3.8 required:
pipenv --python 3.8 install
# If modern Python (3.12.3):
pipenv install
๐ Benefits
โ Isolation
-
Each project has isolated dependencies
-
No system-wide package conflicts
-
Virtual environments stored in project folders
โ Version Control
-
Modern projects use latest Python features
-
Legacy projects maintain compatibility
-
Easy to switch between versions
โ Reproducibility
-
Pipfile.lockensures consistent dependencies -
Clear Python version requirements
-
Easy to share and collaborate
โ ๏ธ Troubleshooting
๐คฉ Common Issues
Wrong Python version in environment
โ Use pipenv --python X.X install explicitly
Package installation failures
โ Check package compatibility with your Python version
Environment not activating
โ Ensure PIPENV_VENV_IN_PROJECT=1 is set
๐พ Verification Commands
# Check current Python
python --version
# Check pipenv Python
pipenv --py
# Check pyenv status
pyenv version
# List environments
pipenv --venv
๐ Best Practices
-
Always use explicit Python versions for legacy projects
-
Commit both
PipfileandPipfile.lock -
Use descriptive project names to separate modern vs legacy
-
Regularly update dependencies in modern projects
-
Test legacy projects after environment changes
๐ Related Tools
-
pyenv โ Python version management
-
pipenv โ Virtual environment & dependency management
-
pip โ Package installer (used internally by pipenv)
Last updated: {{date:YYYY-MM-DD}}