- Install Python on Windows, macOS, or Linux
- Set up a virtual environment for AI projects
- Install core AI libraries with pip
- Verify your setup with a test script
Python is the most popular language for AI development. Most AI libraries, tutorials, and tools are built for Python first. Before you can start building AI projects, you need to set up Python properly on your computer. This guide walks you through every step.
Installing Python#
If you do not already have Python installed, follow these steps for your operating system.
Windows:
- Download Python from the official Python website
- Run the installer
- Tick the box that says "Add Python to PATH", this is important
- Click "Install Now"
- Open Command Prompt and type
python --versionto confirm it installed
macOS:
- macOS comes with an older Python version. Install the latest version using Homebrew
- Open Terminal and run:
brew install python
- Verify with
python3 --version
Linux:
Most Linux distributions include Python. Check your version with python3 --version. If you need to install or update it:
sudo apt update
sudo apt install python3 python3-pip python3-venv
Use Python 3.10 or newer
AI libraries require Python 3.10 or later. Check your version before installing libraries. If you have an older version, update it first.
Setting up a virtual environment#
A virtual environment keeps your AI project's libraries separate from your other Python projects. This prevents version conflicts.
Create a virtual environment:
python3 -m venv my-ai-project
Activate it:
# macOS / Linux
source my-ai-project/bin/activate
# Windows
my-ai-project\Scripts\activate
When the environment is active, you will see the environment name in brackets at the start of your terminal prompt, like (my-ai-project).
To deactivate when you are finished:
deactivate
Always use virtual environments
Installing AI libraries globally can cause conflicts between projects. Always create a virtual environment for each project. It takes seconds and prevents hours of debugging.
Installing essential AI libraries#
With your virtual environment active, install the core libraries you will need. Use pip, which is Python's package manager:
pip install numpy pandas matplotlib scikit-learn jupyter
Here is what each library does:
| Library | Purpose | |---------|---------| | NumPy | Mathematical operations on arrays and matrices | | Pandas | Working with data in tables (like spreadsheets) | | Matplotlib | Creating charts and visualisations | | scikit-learn | Machine learning algorithms for classification, regression, and clustering | | Jupyter | Interactive notebooks for writing and running code in your browser |
For deep learning projects, you will also want:
pip install torch transformers
- PyTorch is a popular deep learning framework
- Transformers by Hugging Face gives you access to pre-trained AI models
Testing your setup#
Create a quick test to make sure everything works. Start a Jupyter notebook:
jupyter notebook
This opens a browser window. Create a new notebook and run this code:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
# Load a sample dataset
iris = load_iris()
df = pd.DataFrame(iris.data, columns=iris.feature_names)
# Show the first few rows
print(df.head())
# Create a simple chart
df.hist(figsize=(10, 8))
plt.tight_layout()
plt.show()
print("Setup complete. All libraries working.")
If you see a table of data and a set of charts, your setup is working correctly.
Next steps#
With your environment ready, you can:
- Work through machine learning tutorials using scikit-learn
- Experiment with pre-trained AI models using the Transformers library
- Build your own data analysis projects with Pandas
- Start learning about neural networks with PyTorch
Key takeaways#
- Python 3.10 or newer is required for modern AI libraries
- Always use a virtual environment for each project
- The core libraries for AI are NumPy, Pandas, Matplotlib, scikit-learn, and Jupyter
- For deep learning, add PyTorch and Transformers
- Test your setup with a simple script before starting a project
- Installing Python
- Setting up a virtual environment
- Installing essential AI libraries
- Testing your setup
- Next steps