✦ Python Intermediate & OOP Local Python project

L2 · Concept 04 · Modules, Packages & Environments

Every project deserves
its own Python environment.

Learn to separate your project libraries, manage dependencies, and prepare a development environment in VS Code.

Learning goalCreate and use a virtual environment, install a library, and save the project dependencies.
01 Learn02 Build locally03 Check your understanding

Learning as a guest

Learning as a guest? Save your progress!

Create a free account to learn with Sloby AI, check your understanding, and track your progress.

The entire platform is free throughout 2026. Foundations stays free forever.

A virtual environment gives one project its own tools.

Imagine two projects that need different versions of the same library. Installing everything globally can cause conflicts. A virtual environment gives each project its own set of installed Python packages.

PROJEKAT A
└── virtuelno okruženje A
    └── njegove biblioteke

PROJEKAT B
└── virtuelno okruženje B
    └── njegove biblioteke

Each project has its own toolbox. A virtual environment isolates project Python packages; it is not a security sandbox or a separate operating system.

The standard Python tool for this is venv. The environment usually lives in a local folder named .venv inside your project.

↳

Two things to keep separate: Activating an environment changes which Python a terminal uses. Selecting an interpreter tells VS Code which Python to use for editing, running, and Python tooling. They are related, but not the same action.

Create .venv from the project folder
python -m venv .venv
# On some macOS/Linux systems:
python3 -m venv .venv

python starts an interpreter, -m venv runs Python’s built-in environment module, and .venv is the folder it creates. Do not edit files inside .venv by hand.

Activate it in your terminal
macOS/Linux:
source .venv/bin/activate

Windows PowerShell:
.\.venv\Scripts\Activate.ps1

Windows Command Prompt:
.venv\Scripts\activate.bat

Leave an activated environment:
deactivate

You can also run the environment’s Python by its direct path without activating it. Use python -m pip when you want pip connected to the Python interpreter you chose.

Install and record a library
python -m pip install requests
python -m pip list
python -m pip freeze > requirements.txt
python -m pip install -r requirements.txt

requests is installed into the selected project environment. requirements.txt records distributions and versions that pip can install again; pip freeze also includes installed dependencies, not only packages you chose directly.

Keep .venv local with .gitignore
.venv/
__pycache__/
*.pyc

Do not send .venv to GitHub: it can be large, depends on the local system, and can be recreated. Keep requirements.txt with the project instead.

Choose the .venv interpreter in VS Code

  1. 1. Open the Command PaletteOpen the Command Palette in VS Code.
  2. 2. Choose Python: Select InterpreterFind and choose Python: Select Interpreter.
  3. 3. Select the Python inside .venvChoose the interpreter that belongs to your project’s .venv, then check that VS Code shows it as selected.

Common virtual-environment problems

  • python is not foundCheck that Python is installed. Try python3 on macOS/Linux; on Windows, use py where Python Launcher is available.
  • A library is not foundCheck the activated environment, the VS Code interpreter, and which environment received the pip install.
  • PowerShell blocks activationWindows execution-policy settings can block scripts. Do not permanently disable security protections; use a Command Prompt terminal or run the Python inside .venv directly instead.
  • .venv is not visibleCheck that the folder was created. Some editor views can hide folders; check the interpreter selection again.

Prepare your first isolated Python project

Do this in VS Code

Work locally in VS Code. Do each command in your project folder and pause to understand what it changes.

Final local project structure
moj_venv_projekat/
├── .venv/
├── .gitignore
├── main.py
└── requirements.txt

.venv stays local. requirements.txt belongs with the project so its dependencies can be recreated.

Build the environment step by step

  1. Create and open moj_venv_projekatCreate a folder named moj_venv_projekat and open it in VS Code.
  2. Create and activate .venvCreate .venv, then use the activation command for your terminal.
    python -m venv .venv
    # or: python3 -m venv .venv
    
    # macOS/Linux: source .venv/bin/activate
    # Windows PowerShell: .\.venv\Scripts\Activate.ps1
  3. Select the VS Code interpreterUse Python: Select Interpreter and choose the interpreter inside .venv.
  4. Install requests and create main.pyInstall requests in this environment. Then create a small file that proves the import works without sending a network request.
    python -m pip install requests
    
    # main.py
    import requests
    
    print("Biblioteka requests je dostupna.")
  5. Record dependencies and ignore .venvCreate requirements.txt and add .venv to .gitignore before you share the project.
    python -m pip freeze > requirements.txt
    
    # .gitignore
    .venv/
    __pycache__/
    *.pyc
  6. Run, then leave the environmentRun python main.py. When you are done in this terminal, use deactivate.
    python main.py
    deactivate
↳

Recreate dependencies later: python -m pip install -r requirements.txt Run this inside a newly created and selected project environment.

Before asking Sloby for help

  • Check the interpreter firstConfirm that VS Code and python -m pip point to the Python inside this project’s .venv.
  • Check the open fileUse Check My Code for the active Python file after your attempt; it reviews code, not the terminal or installed packages.
↳

Next: pip & requirements.txt. You now know why one project needs its own environment. Next you will look more closely at installing and recording project dependencies.

You installed requests in project A’s virtual environment. Is it automatically available in project B’s separate virtual environment?

Think about what a project-specific set of installed packages means.

projekat_a/.venv/  → requests is installed
projekat_b/.venv/  → separate environment
Choose the output

Build independently in VS Code

Create a completely new Python environment

Make a second project folder and repeat the workflow independently before asking Sloby for a hint.

Your goalCreate a new project and .venv, activate it, install requests, write a small program that imports it, create requirements.txt, add .venv/ to .gitignore, and run the program.
drugi_projekat/
├── .venv/
├── .gitignore
├── main.py
└── requirements.txt

Work in your local VS Code folder

Progressive hints
  • Create the project folder before you create .venv.
  • Use python -m venv .venv, then select that interpreter in VS Code.
  • After installing requests, use python -m pip freeze > requirements.txt.

After your attempt, use Ask Sloby for an explanation or Check My Code for the active Python file. Sloby does not run terminal commands, activate environments, or change your files.

Sloby, the Python AI Tutor mascot

Your learning mentor

Sign in to ask Sloby

Create a free account or sign in to get AI guidance while you learn.

Sign in to check your understanding

Create a free account or sign in to receive AI feedback and save your learning progress.

Python AI Tutor · Learn by understanding, not just by running code.