Prepare your environment and start developing Flask applications with Visual Studio Code
Content Index
- ¿ What is Flask and why use it for Python development?
- Flask versus other frameworks
- What is a microframework?
- Flask is extensible: The microframework for creating large projects
- Jinja2 and Werkzeug
- Why Python Flask?
- Why learn Python and Flask to develop our applications?
- ⚙️ Prerequisites for installing Flask
- Verify Python installation
- Install Visual Studio Code and recommended extensions
- Prepare the virtual environment
- Extra: Create in Virtual Environment with VSC
- Install Flask step by step
- Extra: selecting the editor
- Configure Flask in Visual Studio Code
- Run and debug your app from VS Code
- ❓ Frequently Asked Questions about Flask and Visual Studio Code
- Conclusion
If you're taking your first steps in web development with Python, you've surely heard of Flask, a light, flexible, and very powerful microframework. In this guide, I'll teach you how to install Flask in Visual Studio Code (VS Code) and get it ready to create your first web application, regardless of whether you use Windows, macOS, or Linux.
I've been working with various frameworks for a long time—from Django to CodeIgniter—and I assure you that Flask is one of the fastest and cleanest ways to learn how to build web projects with Python.
In this tutorial, we will learn how to install Flask on our computer, regardless of the operating system you are on; since Flask is cross-platform as it is supported by Python; but before that, let's introduce, what is Flask?.
¿ What is Flask and why use it for Python development?
According to the official documentation that you can find at the following link: it is a microframework based on Jinja2 and Werkzeug; here are a few somewhat strange words that we will address next.
Flask is a small framework (a micro framework) that provides the necessary tools and functions to create our applications. It contains the minimum, such as a template engine and HTTP routing and access, and all of this with Python as the programming language supported by this framework.
Flask is a microframework for Python designed to be simple and extensible. It is based on Werkzeug (which manages the server and routes) and Jinja2 (the template engine that allows generating dynamic HTML).
In simple terms: Flask gives you only the essentials to build a web app, without imposing a rigid structure. You decide what modules or extensions to add.
Flask versus other frameworks
When I started working with Flask, I immediately compared it to Django, and the difference was clear: Django brings everything (ORM, authentication, administration, etc.), while Flask gives you total freedom.
To understand it with an analogy that I always use:
“Flask in Python is what CodeIgniter was for PHP, while Django is more like Laravel.”
That flexibility is what makes it ideal for small or medium-sized projects where you want to learn, experiment, or build lightweight APIs.
What is a microframework?
A microframework simply means that the framework only contains the basics to function; if you also develop in CodeIgniter, about which we have a lot of information on our blog, you will know that CodeIgniter is a small framework with many functionalities but lacks a few.
Flask in its basic definition is simpler than CodeIgniter, it does not have libraries or modules for emails, user control, etc.; we only have the routing of the functions and the definition of the templates, and of course, access to the entire Python API, since the framework is written in this programming language.
Flask is extensible: The microframework for creating large projects
What was mentioned in the previous paragraph does not mean that Flask is only useful for basic developments, on the contrary, it is extensible through modules that we can install using Python's package or module management tool, and we have modules of all types, just as we detail and explain the most important ones in the most complete course on Flask in Spanish:
When you learn Flask, you will realize that it has nothing to envy other frameworks like Django; it is a complete framework with which to develop all kinds of applications, simple and not so simple.
That flexibility is what makes it ideal for small or medium-sized projects where you want to learn, experiment, or build lightweight APIs.
Advantages of using Flask
- ✅ Light and easy to learn.
- Highly extensible through modules.
- Cross-platform (Windows, Mac, Linux).
- Perfect for quick projects, prototypes, or medium-sized applications.
Jinja2 and Werkzeug
Jinja2 is the template engine that Flask uses and Werkzeug is the library that contains different utilities or functions for HTTP, such as the definition of routes, redirects, etc.: it is also our WSGI, which is the Python interface that allows us to communicate via HTTP.
Why Python Flask?
Surely when you hear web programming with Python, Django comes to mind, which is an excellent web framework for Python that already contains everything necessary to make our apps, but Flask, being the minimal expression of a framework or microframework, we have more control over the different elements of our framework, installing just what is necessary and it is also easier to learn than Django. This does not mean that Flask is better than Django or vice versa, they are simply two different versions for the same objective, which is the development of web apps with Python; in my opinion, Flask works excellently for us in small or medium-sized projects, while we could use Django for larger projects.
"Flask Python is the CodeIgniter of php and Django is the Laravel of php"
To close this section, I show you a small and minimal app in Flask:
@app.route('/') def hello_world():
return 'Hello Flask' And this is all we need to make a hello world in Flask (of course, once the framework is installed); a file with the previous definition, where we have the routing thanks to our Werkzeug, the function that is the action or function of our controller, and the response which is simply text, and therefore at this moment we are not using the Jinja2 template engine; now, in Django we need much more than this to start working, hence the comment above.
Why learn Python and Flask to develop our applications?
Python is an exceptional language, employed by major companies like Microsoft, which offers free courses on how to start with this programming language. It is fast, cross-platform, and easy to learn compared to others like the older Java.
And best of all
Is that if you know Python, you can create anything from desktop apps, games, Artificial Intelligence (AI) probability procedures, and of course, create web apps as we mentioned before; in fact, Python is the programming language selected to create the famous Blender.
Therefore, it is an exceptional language, constantly growing, and what better than to use it in web programming, which is the creation of systems that are in constant demand and growth, such that with this you can have multiple advantages such as professional growth, since in short, Flask is the best web framework you can select if you are learning to program and/or creating your first web apps in general or based on Python.
⚙️ Prerequisites for installing Flask
Before you begin, make sure you have these items installed:
Verify Python installation
Open your terminal or console (PowerShell, CMD, or macOS/Linux terminal) and run:
python --versionIf you get a 3.x version, you can continue. If not, download and install Python from python.org
Install Visual Studio Code and recommended extensions
I use Visual Studio Code because it is light, cross-platform, and has specific extensions for Python.
Install it from code.visualstudio.com
Then, within VS Code:
Open the extensions tab (Ctrl+Shift+X).
Install Python (from Microsoft).
Optionally, add Pylance and Code Runner for autocompletion and fast execution.
Prepare the virtual environment
Creating a virtual environment allows you to isolate dependencies:
$ python -m venv venvWe have a specific article with which you can learn to create the virtual environment in Flask.
Extra: Create in Virtual Environment with VSC
With VS Code, you can create the virtual environment. To do so, you must have the Python extension for VSC installed.
Let's create an empty folder. In my case, I'll use:
proy/
└─ hello
I drag that folder into VS Code before creating the environment to avoid errors.
Press Ctrl + Shift + P (or Command + Shift + P on Mac) in VSC and search for:
Create EnvironmentI select Python as the interpreter, and the virtual environment will automatically start being created within .venv.
Install Flask step by step
Finally we will get to the point that interests us, installing Flask, which, like Python, is cross-platform, remember that just having Python in its latest versions is enough to follow this guide and thus get your Flask; to install Flask we can do it using pip: pip install flask
With your virtual environment active, install Flask with pip:
$ pip install flaskTo verify that the installation was successful:
$ pip show flaskYou will see the version of Flask that you have installed; and with this you can continue with the next tutorial:
Extra: selecting the editor
Now, for the editor you can use any one you feel comfortable with for working with Python, but I personally recommend Visual Studio Code, which is cross-platform and you can develop all kinds of projects based on other frameworks in the same editor.
Configure Flask in Visual Studio Code
Open the project and select the virtual environment
- Open the project folder in VS Code.
- In the lower right corner, select the Python interpreter corresponding to your virtual environment (venv).
- Verify that the Flask commands run from the integrated terminal.
Run and debug your app from VS Code
Press F5 or go to Run > Start Debugging.
VS Code will automatically detect your Flask app and open the server.
❓ Frequently Asked Questions about Flask and Visual Studio Code
What version of Python do I need?
Any version 3.7 or higher works perfectly.
Can I use Flask on macOS or Linux?
Yes. Only the virtual environment activation command changes.
How do I know if Flask is installed correctly?
Run pip show flask or launch the Hello World. If the server opens on localhost, everything is correct.
What do I do if VS Code doesn't detect my virtual environment?
Restart the VS Code window and manually select the Python interpreter from the bottom bar.
Conclusion
Installing Flask in Visual Studio Code is simple if you follow the correct steps:
- Install Python.
- Configure your virtual environment.
- Install Flask with pip.
- Use VS Code to run and debug your app.
And remember: Flask is not just for beginners. It's a powerful, flexible tool ready to scale your ideas, just like when I discovered it and started creating my first APIs in minutes.
The next thing you should learn to do is, a Hello World in Flask.
I agree to receive announcements of interest about this Blog.
In this tutorial we are going to learn how to install Flask on our computer, regardless of the operating system in which you are; since Flask is cross-platform since it is supported in Python; but before this, let's introduce, what is Flask.