0%

Your Own Machine, Your Own Editor

Use the Project's Python

Chapter 3 separated a project’s Python from every other project’s packages. Do the same thing here, inside the integrated whose location you just checked.

The commands below lead with the explicit interpreter path. They work even when activation is unavailable, and they make every pip and Python pairing visible.

python3 --version
python3 -m venv .venv
./.venv/bin/python -m pip install -r requirements.txt
./.venv/bin/python ./hello.py

The final command should print Hello from your own machine!.

Activation is optional. If you prefer it, run source .venv/bin/activate; after that, the shorter python ./hello.py uses the active environment.

Some distributions package the venv support separately. If creation reports that ensurepip or venv is unavailable, use the distribution’s software manager or administrator-supported Python package, then retry. Do not use a broad permission change as a fix.

Select the same interpreter in the editor

The terminal command chose .venv explicitly. The editor’s Run button has its own interpreter setting.

In Visual Studio Code, open the Command Palette and choose Python: Select Interpreter, then select the interpreter inside this project’s .venv. The displayed path should belong to the folder you opened. If the command is absent, use the editor’s supported Python extension or your editor’s equivalent interpreter setting; do not install an unrelated extension with a similar name.

Press Run with hello.py open. The same greeting should appear. This observable run is for you. The final token does not claim that Python Land saw the editor setting or this separate run.

Recover by reading the failed layer

  • If python3 or py is not found during creation, use the installation instructions in Create and Activate .venv (Chapter 3), or use the site-only route. A cannot create its base Python.

  • If the version is Python 3.9 or older, select or install Python 3.10 or newer before creating .venv. The exact requests release in this project does not install on Python 3.9.

  • If Python cannot open hello.py, run pwd and check that the editor terminal is still at the project root.

  • If pip cannot find requirements.txt, the same working-directory check comes first.

  • If requests fails to install, keep the exact pin. Read whether pip reports no matching release or a connection failure before changing anything.

  • If the editor’s Run button behaves differently from the explicit terminal command, reselect the .venv interpreter. Do not rebuild an environment that the explicit path has already proved works.

You now have the local result the chapter was aiming for. The final lesson asks the selected interpreter to report a narrow set of facts, then lets you decide whether to send that report back.

Why do the commands name ./.venv/bin/python explicitly instead of relying on activation?

The terminal command works, but the editor's Run button behaves differently. What is the likely cause?