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.
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
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.