Setting up the Python development environment involves installing Python, configuring an IDE, running Python scripts, and managing Python packages.

Installing Python

To start programming in Python, you first need to install Python on your system.

  • Download Python: Visit the official Python website and download the installer for your operating system (Windows, macOS, or Linux).

  • Installation Instructions:

    • Windows:

      1. Run the installer and ensure you check the box “Add Python to PATH.”
      2. Follow the prompts to complete the installation.
    • macOS:

      1. Download the .pkg installer from the Python website.
      2. Run the installer and follow the instructions.
    • Linux:

      1. Most Linux distributions come with Python pre-installed. If not, use the package manager to install it. For example:
          sudo apt-get install python3
          

Setting up an IDE (PyCharm, VSCode, etc.)

An Integrated Development Environment (IDE) can help you write and manage your Python code more efficiently.

  • PyCharm:

    • Overview: A popular IDE specifically for Python development.
    • Installation:
      1. Download PyCharm from the official website.
      2. Run the installer and follow the prompts.
  • Visual Studio Code (VSCode):

    • Overview: A lightweight, versatile code editor with support for Python through extensions.
    • Installation:
      1. Download VSCode from the official website.
      2. Run the installer and follow the prompts.
    • Setting Up Python Extension:
      1. Open VSCode.
      2. Go to Extensions (Ctrl+Shift+X) and search for “Python.”
      3. Install the Python extension by Microsoft.

Running Python Scripts

Once Python and your IDE are set up, you can start running Python scripts.

  • Using the Command Line:

    1. Open your terminal or command prompt.
    2. Navigate to the directory containing your Python script.
    3. Run the script with:
        python script.py
        
  • Using an IDE:

    • Open your Python script in your chosen IDE.
    • Look for the “Run” button or use the IDE’s built-in terminal to execute the script.

Python Package Management (pip)

pip is the package installer for Python, allowing you to install and manage additional libraries and packages.

  • Installing Packages:
      pip install package_name
      
  • Upgrading Packages:
  pip install --upgrade package_name
  
  • Listing Installed Packages:
  pip list
  
  • Uninstalling Packages:
  pip uninstall package_name
  

With Python installed, an IDE configured, and package management set up, you’re ready to start developing Python applications and leveraging the extensive Python ecosystem.

pyenv for Multiple Python Versions

  # macOS
brew install pyenv
pyenv install 3.12.0
pyenv global 3.12.0

python --version  # 3.12.0
  

Create a .python-version file in a project to pin the version locally.

uv — Fast Modern Tooling

  curl -LsSf https://astral.sh/uv/install.sh | sh
uv venv
uv pip install requests
uv pip compile requirements.in -o requirements.txt
  

uv is significantly faster than pip for installs and resolves dependencies quickly.

Verifying Your Setup

  python --version
pip --version
python -c "import sys; print(sys.executable)"
  

Confirm the executable points to your venv when one is active.

Creating a requirements.txt

  pip freeze > requirements.txt
pip install -r requirements.txt
  

For applications, pin exact versions. For libraries, specify ranges in pyproject.toml.

Troubleshooting

Issue Solution
python not found Use python3; add to PATH on Windows install
pip installs to system Activate venv first
SSL errors on pip Upgrade pip: pip install --upgrade pip
Wrong version running Check which python and pyenv/venv activation