Python Project in VS Code: Virtual Environment, Pip & Extensions (Step-by-Step Guide)

by John

 

Welcome to Part 3 of our comprehensive guide on setting up a Python development environment on Windows. In this installment we will show how to create a Python virtual environment, install third party packages with pip. In addition we will show how to make the project in to a package in order to avoid errors related to Python imports. 

 

In the previous sections, we covered: Setting up a Python Dev Environment on Windows, if you haven't followed this section and are running in to Python path errors, or pip not found errors, I suggest you read the previous post. 

 

Intro: Folders 📁 & VS Code

 

When setting up a Python development environment—whether you're a total beginner, an expert, or somewhere in between—it's always a good idea to make accessing and creating new folders as easy as possible. It's easy to procrastinate if there are even the smallest obstacles in the way!

 

Plus, once you have a lot of folders locally, it becomes easy to lose track of them. Side note: If this already sounds like you, you might want to check out this guide on setting up GitHub Desktop.

 

When setting up a new machine, I usually create a folder 📁 -> Document/PythonProjects to store down all my projects. 

 

Python Dev Environment , Create Folder Step 1

 

 


 

Create new Python Project folder & Open in Vs Code

 

Ok so if you already find yourself at this screen in Vs Code, ❌ Vs Code entirely, and go back to your folder from previous section. 

 

New Python Project with Vs Code

 

 

In my Documents/PythonProjects folder, I create a new folder called FirstProject. Its usually easy to create your new project folder outside of Vs Code, and then just open it with ➡️ a right click ➡️ Show more options ➡️ Open with Code

 

 

Open A folder with Vs Code, new Python Project

 

 


 

Create A Virtual Environment

 

What is a Python Virutal Environment?

In Python, a virtual environment is a setup that allows you to keep all your project-specific packages and dependencies separate from the system-wide ones. It’s quite useful when you’ve multiple projects, each needing different versions of the same libraries. Without a virtual environment, things can get messy quickly! 

 

Command to Create one In Vs Code

 

 

 

 

Then type command below ⬇️ to create it. Note that sometimes you will see it called .venv , so you could also do python -m venv .venv, or call it something else (but that's not recommended). 

python -m venv venv

 

 

You should see up in the file section there has been a folder called venv created ⬇️