Python Setup + Virtual Environment — Complete Beginner Guide

Python Tutorial Topics — Complete Roadmap

If you are starting your journey with Python, the first step is to set up your development environment correctly. A proper setup makes it easier to install packages, manage dependencies, and work on multiple projects without conflicts.

In this tutorial, we will learn how to install Python, understand pip, create a virtual environment, configure VS Code, and build our first Python project. This guide is designed for beginners who want to start learning Python for AI, automation, backend development, or other programming tasks.

By the end of this tutorial, you will have a working Python project with its own virtual environment and a basic understanding of how Python projects are organized.

What You Will Learn

  • How to install Python on Windows
  • How to check the Python and pip versions
  • What pip is and why it is used
  • What a virtual environment is
  • How to create and activate a virtual environment
  • How to configure Python in VS Code
  • How to create a basic Python project structure
  • How to install packages using pip
  • How to generate and use requirements.txt
  • How to run your first Python program

Prerequisites

You do not need any advanced Python knowledge for this tutorial. Basic computer knowledge and a code editor such as VS Code are enough to get started.

If you already know PHP or Laravel, some concepts will feel familiar. For example, Python’s pip is similar to PHP’s Composer, while a virtual environment helps keep project dependencies isolated.

Let’s begin.

1. What Is Python?

Python is a high-level, general-purpose programming language known for its simple syntax and readability. It is widely used in:

  • Artificial Intelligence and Machine Learning
  • Backend development
  • Automation
  • Data analysis
  • Web scraping
  • API development
  • Chatbots
  • Retrieval-Augmented Generation (RAG) applications

Python is a great language for beginners because its syntax is easy to understand, while it also provides powerful libraries for advanced development.

2. Install Python

First, download Python from the official website:

Download Python

Choose the latest stable version available for your operating system.

Windows Installation

  1. Open the Python installer.
  2. Check Add python.exe to PATH.
  3. Click Install Now.
  4. Wait for the installation to complete.

Adding Python to PATH allows you to run Python commands directly from the terminal.

Check Python Installation

Open CMD or the VS Code terminal and run:

python --version

You should see output similar to:

Python 3.x.x

If the python command does not work on Windows, try:

py --version

Check pip

pip --version

You can also use:

python -m pip --version

If both commands work, your Python installation is ready.

3. What Is pip?

pip is Python’s package installer. It allows you to install and manage external Python libraries.

For example, if you want to work with HTTP requests, you can install the requests library:

pip install requests

This is similar to installing a PHP package using Composer:

composer require guzzlehttp/guzzle

Useful pip Commands

pip list

Displays installed packages.

pip show requests

Displays information about a specific package.

pip uninstall requests

Removes a package.

pip freeze

Displays installed packages and their versions.

4. What Is a Virtual Environment?

A virtual environment is an isolated Python environment created for a specific project. It allows each project to have its own dependencies and package versions.

For example, one project may require an older version of a library, while another project may require a newer version. Installing everything globally can create conflicts.

A virtual environment solves this problem by keeping project dependencies separate.

Example

Project A
└── .venv
    └── Project-specific packages

Project B
└── .venv
    └── Different project-specific packages

Each project can manage its dependencies independently.

A virtual environment is one of the most important concepts to understand when starting Python development.

5. Create a Virtual Environment

Create a folder for your project:

mkdir python-learning
cd python-learning

Now create a virtual environment:

python -m venv .venv

If the python command does not work, use:

py -m venv .venv

Understanding the Command

python       → Runs Python
-m venv      → Runs Python's built-in virtual environment module
.venv        → Name of the virtual environment folder

After running the command, your project will contain a .venv folder.

6. Activate the Virtual Environment

Windows CMD

.venv\Scripts\activate

Windows PowerShell

.venv\Scripts\Activate.ps1

After activation, you will see (.venv) at the beginning of your terminal prompt:

(.venv) C:\...\python-learning>

This indicates that the virtual environment is active.

Deactivate the Environment

When you want to leave the virtual environment, run:

deactivate

7. Set Up VS Code for Python

Download and install VS Code from the official website:

Download VS Code

Then follow these steps:

  1. Open VS Code.
  2. Select File → Open Folder.
  3. Open your python-learning folder.
  4. Open the Extensions panel.
  5. Search for Python.
  6. Install the Python extension by Microsoft.

The extension provides Python support, code completion, debugging, and interpreter selection.

Select the Python Interpreter

Press:

Ctrl + Shift + P

Search for:

Python: Select Interpreter

Select the interpreter associated with your .venv folder.

This ensures that VS Code uses the correct Python environment for your project.

8. Create Your First Python Project

Create the following files and folders:

python-learning/

├── .venv/
├── app.py
├── requirements.txt
├── .gitignore
└── README.md

Purpose of Each File

File / FolderPurpose
.venv/Stores the isolated Python environment
app.pyContains the main Python code
requirements.txtLists project dependencies
.gitignoreSpecifies files Git should ignore
README.mdContains project documentation

Python does not require one fixed project structure. You can organize your project based on its size and requirements.

9. Write Your First Python Program

Open app.py and add:

print("Hello, Python!")
print("I am learning AI development.")

Run the program:

python app.py

Expected output:

Hello, Python!
I am learning AI development.

Congratulations! You have successfully run your first Python program.

10. Install and Test a Python Package

Make sure your virtual environment is active, then install the requests package:

pip install requests

Update app.py:

import requests

response = requests.get("https://example.com")

print("Status Code:", response.status_code)

Run the program:

python app.py

If everything is working correctly, you should see a successful HTTP status code.

11. What Is requirements.txt?

The requirements.txt file stores the packages required by your project.

For example, after installing packages, you can generate the file using:

pip freeze > requirements.txt

This saves the installed package names and versions.

Install Dependencies on Another Computer

If someone else wants to run your project, they can install all dependencies using:

pip install -r requirements.txt

This is similar to running composer install in a PHP project.

12. Create a .gitignore File

Create a .gitignore file in your project root:

.venv/
__pycache__/
.env

This prevents unnecessary or sensitive files from being committed to Git.

You generally should not upload the .venv folder to GitHub because it contains environment-specific files.

13. Complete Project Setup Commands

Here is the complete setup flow:

mkdir python-learning
cd python-learning

python -m venv .venv

.venv\Scripts\activate

pip install requests

python app.py

pip freeze > requirements.txt

14. Common Errors

Python Is Not Recognized

If you see an error such as python is not recognized, Python may not be added to PATH.

Try:

py --version

If that also fails, reinstall Python and make sure Add python.exe to PATH is selected.

No Module Named requests

This usually means the package is not installed in the current environment or VS Code is using the wrong interpreter.

Try:

python -m pip install requests

Also check that your .venv is activated.

PowerShell Activation Error

If PowerShell blocks the activation script, you can use CMD and run:

.venv\Scripts\activate

Conclusion

In this tutorial, we learned how to install Python, use pip, create a virtual environment, configure VS Code, and set up our first Python project.

A proper development environment is the foundation of every Python project. Once you understand these basics, you can start learning Python programming and move toward advanced topics such as APIs, AI, Machine Learning, and RAG.

No comments yet! You be the first to comment.

Leave a Reply

Your email address will not be published. Required fields are marked *