Table of contents
  1. Install
    1. Using PyEnv
  2. Working with Virtual Environments





Install

Using PyEnv

  1. Install pyenv using Homebrew:
         brew install pyenv
    
  2. Add pyenv to your shell configuration. For zsh (default in newer macOS), add these lines to your ~/.zshrc file:
         echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
         echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
         echo 'eval "$(pyenv init --path)"' >> ~/.zshrc
    
  3. Install the Python version you need:
         pyenv install 3.10.x
    
  4. Set it as your global Python:
         pyenv global 3.10.x
    

Working with Virtual Environments

Virtual environments are an essential tool for modern Python development. They create isolated spaces where you can install packages without affecting your
system-wide Python installation. This prevents dependency conflicts between different projects.

  • Here's how to create and use a virtual environment:
    1. Create a new virtual environment :
      python3 -m venv my_project_env
      
    2. Activate the virtual environment:
       source my_project_env/bin/activate
      
    3. Your terminal prompt will change to show the active environment. Now you can install packages that will only affect this environment:
       pip install package_name
      
    4. When you’re done, deactivate the environment:
       deactivate