Skip to main content

Python Installation

Python is a powerful, versatile programming language that's perfect for beginners and professionals alike. This guide will walk you through installing Python 3 on various operating systems and configuring your environment for optimal use.

info

The instructions in this guide are for Python 3.x, which is the recommended version for all new Python projects.

Installation by Operating System

macOS Installation

  1. Download the installer:
  1. Run the installer:
  • Open the downloaded .pkg file
  • Follow the installation wizard instructions
  1. Verify installation:
  • Open Terminal (from Applications > Utilities or using Spotlight search)
  • Type python3 --version and press Enter

Using Homebrew

  1. Install Homebrew (if not already installed):
bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Then you will see...

  1. Install Python:
bash
brew install python
  1. Verify installation:
bash
python3 --version
info

On macOS, the system comes with a pre-installed version of Python 2.7. Always use python3 to ensure you're using Python 3.

Verifying Your Installation

After installing Python, verify that everything is working correctly:

bash
# Check Python version
python --version # or python3 --version on some systems

# Start the Python interpreter
python # or python3 on some systems

# In the interpreter, try a simple command
print("Hello, World!")

# Exit the interpreter (Ctrl+Z on Windows, Ctrl+D on Unix, or type:)
exit()
success

If you see the Python version displayed and can run the interpreter, your installation was successful!

Configuring Your IDE

What is an IDE?

An Integrated Development Environment (IDE) is a software application that provides comprehensive facilities to programmers for software development. It typically includes a code editor, debugger, and build automation tools.

  1. Install VS Code:
  1. Install Python extension:
  • Open VS Code
  • Go to Extensions view (Ctrl+Shift+X or Cmd+Shift+X)
  • Search for "Python"
  • Install the Microsoft Python extension
  1. Configure Python interpreter:
  • Press Ctrl+Shift+P (or Cmd+Shift+P on macOS)
  • Type "Python: Select Interpreter"
  • Choose your installed Python version or virtual environment
tip

VS Code offers excellent debugging tools for Python. To start debugging, add a breakpoint by clicking in the left margin next to your code, then press F5.

Troubleshooting Common Issues

Python Command Not Found

If you get a "command not found" error:

Windows:

  • Ensure Python is added to PATH
  • Try using py instead of python

macOS/Linux:

  • Try using python3 instead of python
  • Check if Python is installed: which python3
pip Not Working

If pip commands fail:

  • Update pip: python -m pip install --upgrade pip
  • On some systems, use pip3 instead of pip
  • Make sure you're in the correct virtual environment
Path Issues

If modules can't be found after installation:

  • Check your PYTHONPATH environment variable
  • Make sure you're installing packages in the active virtual environment
Permission Errors

If you get permission errors:

  • On Windows: Run Command Prompt as Administrator
  • On macOS/Linux: Use sudo or install packages with the --user flag:
bash
pip install --user package_name

Basic Python Configuration (Optional)

Creating a .pyrc File

You can create a Python startup file that runs every time you start the Python interpreter:

python
# ~/.pyrc or ~/.pystartup
# Add commonly used imports
import os
import sys
import math
import datetime as dt

# Define useful functions
def cls():
os.system('cls' if os.name == 'nt' else 'clear')

# Set environment variables
os.environ['PYTHONDONTWRITEBYTECODE'] = '1' # Don't create .pyc files

Then add to your shell profile:

bash
# Add to .bashrc, .zshrc, etc.
export PYTHONSTARTUP=~/.pyrc

Environment Variables

Important Python environment variables:

bash
# Control where Python looks for modules
export PYTHONPATH=/path/to/your/modules

# Don't create .pyc files
export PYTHONDONTWRITEBYTECODE=1

# Display warning messages
export PYTHONWARNINGS=default

Next Steps

Now that you have Python installed and configured, you can start learning and building projects! Here are some recommended starting points:

  1. Try a simple "Hello World" program
  2. Learn basic Python syntax and data structures
  3. Explore the Python Standard Library
  4. Build small projects to practice your skills
success

Remember, the best way to learn programming is by doing. Start with small projects and gradually build your skills!



If you spot any mistakes on this website, please let me know at [email protected]. I’d greatly appreciate your feedback! :)