Set Up Python and Libraries for AI

For Ubuntu

For MacOS

Set Up a Virtual Environment

1. Install Python 3.10

Tensorflow for MacOS currently (8/26/2025) requires python 3.9 or 3.10, it won't work with newer versions

This will install Python 3.10 on your computer at a location like: /usr/local/bin/python3.10

2. Create a Virtual Environment

Navigate to your project directory or create one:

Then create the virtual environment1:

This creates a folder named venv containing the isolated Python environment.

3. Activate the Environment

Your terminal prompt will change to show you're inside the virtual environment. Now any pip3 install commands will apply only to this project.


4. Install Your Packages

Install the dependencies for this project:


5. Deactivate When Done

To exit the virtual environment:

 


Creative Commons License AI Programming lecture notes by Brian Bird, written in , are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

MS Copilot GPT-4 was used to draft parts of these notes.


1 A Python virtual environment is like a sandbox for your Python projects—it isolates dependencies so that each project can have its own specific versions of packages, without interfering with others or your system-wide Python setup. It creates a folder (venv) containing: a) A copy of the Python interpreter. b) A local pip installer. c) A clean site-packages directory for your project’s dependencies. When you activate it, your shell temporarily switches to using that isolated Python and pip.