Python Setup + Virtual Environment — Complete Beginner Guide
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:
Choose the latest stable version available for your operating system.
Windows Installation
- Open the Python installer.
- Check Add python.exe to PATH.
- Click Install Now.
- 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 --versionYou should see output similar to:
Python 3.x.xIf the python command does not work on Windows, try:
py --versionCheck pip
pip --versionYou can also use:
python -m pip --versionIf 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 requestsThis is similar to installing a PHP package using Composer:
composer require guzzlehttp/guzzleUseful pip Commands
pip listDisplays installed packages.
pip show requestsDisplays information about a specific package.
pip uninstall requestsRemoves a package.
pip freezeDisplays 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 packagesEach 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-learningNow create a virtual environment:
python -m venv .venvIf the python command does not work, use:
py -m venv .venvUnderstanding the Command
python → Runs Python
-m venv → Runs Python's built-in virtual environment module
.venv → Name of the virtual environment folderAfter running the command, your project will contain a .venv folder.
6. Activate the Virtual Environment
Windows CMD
.venv\Scripts\activateWindows PowerShell
.venv\Scripts\Activate.ps1After 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:
deactivate7. Set Up VS Code for Python
Download and install VS Code from the official website:
Then follow these steps:
- Open VS Code.
- Select File → Open Folder.
- Open your
python-learningfolder. - Open the Extensions panel.
- Search for Python.
- Install the Python extension by Microsoft.
The extension provides Python support, code completion, debugging, and interpreter selection.
Select the Python Interpreter
Press:
Ctrl + Shift + PSearch for:
Python: Select InterpreterSelect 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.mdPurpose of Each File
| File / Folder | Purpose |
|---|---|
.venv/ | Stores the isolated Python environment |
app.py | Contains the main Python code |
requirements.txt | Lists project dependencies |
.gitignore | Specifies files Git should ignore |
README.md | Contains 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.pyExpected 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 requestsUpdate app.py:
import requests
response = requests.get("https://example.com")
print("Status Code:", response.status_code)Run the program:
python app.pyIf 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.txtThis 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.txtThis 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__/
.envThis 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.txt14. 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 --versionIf 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 requestsAlso check that your .venv is activated.
PowerShell Activation Error
If PowerShell blocks the activation script, you can use CMD and run:
.venv\Scripts\activateConclusion
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.
