Local Python Environments

Create a local project environment, identify its interpreter, and install a third-party package through that same interpreter.

Python in the browser is ready when a lesson opens. A project on your own computer needs one more decision: which Python interpreter and installed packages belong to that project?

This page is optional setup material. You do not need it to complete the chapter. Return when you choose to run a later third-party example locally.

One environment per project

A virtual environment is a folder containing a Python interpreter and the packages installed for one project. It keeps one project's package choices from silently changing another project.

From the project folder, create an environment:

python -m venv .venv

You can use that interpreter directly without relying on shell activation. On macOS or Linux:

.venv/bin/python -m pip install numpy

On Windows PowerShell or Command Prompt:

.venv\Scripts\python.exe -m pip install numpy

To inspect the interpreter from Python, run the same environment interpreter and print its path:

The printed path should point into the project's .venv folder.

Install through the selected interpreter

If you activate the environment using the command documented for your shell, the shorter form is:

python -m pip install numpy

In either form, the selected Python interpreter runs the package installer. If an import fails after installation, compare sys.executable with the interpreter used for -m pip before installing the package again.

Browser Python and local Python are separate

The runnable editors on LLM Primer use a Python environment inside the browser. Packages loaded there are not installed into your computer's project environment. Files created in the browser runner are also separate from files in your local project folder.

Keep that boundary in mind when moving an example from a lesson into a local project: recreate the required input files, select the intended interpreter, and install only the packages the project actually uses.

Use a project environment when local work needs third-party packages. First identify the interpreter; then install through that same interpreter.

Pause and reflect

In your own words, note what you understood, what remains unclear, or what you want to revisit. The note stays with this lesson.

Review

Not marked done.