Python

Complete guide to installing and configuring Python on your system

What is Python?

Python is an interpreted, high-level programming language with clear, readable syntax. It's multi-paradigm and used in web development, data science, artificial intelligence, automation and more.

🔄 Multi-paradigm

Supports object-oriented, imperative and functional programming

📚 Extensive Libraries

Extensive ecosystem with libraries for almost any task

🚀 Easy to Learn

Clear, readable syntax, ideal for beginners

🌐 Cross-platform

Works on Windows, macOS, Linux and other systems

Installing Python

Step 1: Download Python

Visit the official Python.org and download the latest stable version for your operating system.

Recommendation: Download Python 3.x (the most recent version)

Step 2: Run the installer

Run the downloaded file (.exe in Windows, .pkg in macOS, .tar.xz in Linux).

Windows - Executable installer:

python-3.x.x-amd64.exe

Step 3: Configure the installation (Windows)

During installation on Windows, make sure to check these important options:

  • "Add Python to PATH" - Essential for accessing Python from anywhere
  • "Install launcher for all users" - Recommended
  • "Customize installation" - For advanced options

Step 4: Finish installation

Complete the installation and verify that Python was installed correctly.

Verifying the installation

Check the Python version

Open your terminal or command line and run:

Verify installation:

python --version

Or alternatively:

python3 --version

Accessing the Python interpreter

Run Python in interactive mode:

Terminal/Console:

$ python
Python 3.11.0 (default, Oct 24 2022, 18:26:48)
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Configuring the PATH

What is the PATH?

The PATH is a system variable that tells the operating system where to look for executables. It's crucial for Python to be in the PATH so you can run it from any directory.

Check if Python is in the PATH

Windows (CMD):

where python

Linux/Mac (Terminal):

which python3

Windows - Add to PATH manually

Step 1: Find the installation path

Find where Python is installed. Usually at:

C:\Users\[Usuario]\AppData\Local\Programs\Python\Python311\

Or

C:\Program Files\Python311\
Step 2: Open environment variables
  • Press Windows + R, type sysdm.cpl and press Enter
  • Click "Environment Variables"
  • On "System Variables", look for "Path" and click "Edit"
Step 3: Add the paths

Add these two paths (replace with your version):

C:\Program Files\Python311\ C:\Program Files\Python311\Scripts\
Step 4: Verify

Close and open a new CMD window and run:

python --version

Linux/Mac - Add to PATH

On Linux and macOS, Python is usually already in the PATH. If you need to add it manually:

Add to .bashrc or .zshrc:
export PATH="/usr/local/bin/python3:$PATH"

Then run:

source ~/.bashrc

First program in Python

Create a test file

Create a file named hola_mundo.py with the following content:

# My first program in Pythonprint("¡Hola Mundo!")

# Variables and operationsnombre = "Ana"
edad = 25
print(f"Me llamo {nombre} y tengo {edad} años")

# Math operationsresultado = 10 + 5
print(f"10 + 5 = {resultado}")

Run the program

From the terminal, navigate to the file's directory and run:

python hola_mundo.py

Or if you're using Python 3 specifically:

python3 hola_mundo.py

Expected output:

¡Hola Mundo!
Me llamo Ana y tengo 25 años
10 + 5 = 15

Virtual Environments (Virtualenv)

Why use virtual environments?

Virtual environments let you isolate the dependencies of different Python projects, avoiding conflicts between library versions.

Create a virtual environment

Create environment:

python -m venv mi_entorno

Activate environment (Windows):

mi_entorno\Scripts\activate

Activate environment (Linux/Mac):

source mi_entorno/bin/activate

Deactivate environment:

deactivate

Installing libraries with pip

What is pip?

pip is Python's package manager. It lets you install and manage third-party libraries.

Basic commands of pip

Install a library:

pip install nombre_libreria

Install a specific version:

pip install nombre_libreria==1.2.3

List installed libraries:

pip list

Save dependencies to a file:

pip freeze > requirements.txt

Install from requirements.txt:

pip install -r requirements.txt

Popular libraries to get started

📊 NumPy

Numerical computing and arrays

pip install numpy

🐼 Pandas

Data analysis and manipulation

pip install pandas

📈 Matplotlib

Charts and visualizations

pip install matplotlib

🌐 Requests

Simple HTTP requests

pip install requests

Common troubleshooting

'python' is not recognized as a command

Python is not in the PATH. Check the PATH configuration section or reinstall Python checking "Add Python to PATH".

Conflict with Python 2 and 3

On some systems, 'python' runs Python 2 and 'python3' runs Python 3. Use 'python3' to make sure.

Permission error when installing packages

On Linux/macOS, don't use sudo with pip. Better to use virtual environments or the --user.

Fixing common issues with pip

Issue: pip is not installed

In some Python installations, pip is not included.

Solution - Download get-pip.py:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Run:
python get-pip.py
Issue: Permission error

On Unix systems, installing packages globally may require superuser permissions.

Option 1 - Use --user:
pip install --user nombre_paquete
Option 2 - Use a virtual environment (recommended):
python -m venv mi_entorno
source mi_entorno/bin/activate
pip install nombre_paquete
Issue: pip outdated

Update pip to the latest version:

python -m pip install --upgrade pip
Issue: Timeout or slow connection

Use the mirror for pip or increase timeout:

With timeout extended:
pip install --timeout=1000 nombre_paquete
Use the mirror for Tsinghua (China):
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple nombre_paquete

🎯 Next Steps

Learn Python Basics

  • Variables and data types
  • Control structures (if, for, while)
  • Functions and modules
  • File handling

Practical Projects

  • Simple calculator
  • Guessing game
  • Basic web scraper
  • Task automation