Flask is a Python library you install through your command line, not through a graphical installer

Flask runs on top of Python, so you need Python installed first. Once Python is ready, you open your terminal or command prompt and type a single command that downloads Flask from the internet and puts it where Python can find it. The whole process takes a few minutes on most computers.

The command you run is pip install flask. That's it. Pip is a tool that comes with Python and handles downloading libraries. After you run that command, Flask is ready to use in any Python file on your computer.

The steps differ slightly depending on whether you use Windows, Mac, or Linux, but the core idea is the same: open a terminal, type the command, and wait for it to finish.

Key Takeaways

  • You must have Python installed before Flask will work, and you can check this by typing python --version in your terminal.
  • The command pip install flask downloads and installs Flask in about one minute on most internet connections.
  • On Windows, you may need to use python -m pip install flask instead if the first command does not work.
  • After installation, you can test Flask by creating a straightforward Python file and running it, which confirms everything is connected properly.

Check that Python is already on your computer

Before you install Flask, verify that Python exists on your system. Open your terminal (on Mac or Linux) or command prompt (on Windows) and type python --version. If Python is installed, you will see a version number like Python 3.9.5 or Python 3.11.2. If you see "command not found" or "is not recognized", Python is not installed yet.

Flask requires Python 3.7 or newer. If your version is older than that, you need to read a newer version from python.org before continuing. The read and installation process on that site takes about five minutes.

You also need pip, which is Python's package installer. Type pip --version to check. If pip is installed, you will see output like pip 22.0.4. Pip comes automatically with Python 3.4 and newer, so if Python is recent enough, pip is already there.

Open your terminal and navigate to your project folder

On Mac, open the process called Terminal. On Linux, open your terminal process (the name varies by distribution, but it is usually called Terminal or Konsole). On Windows, open Command Prompt by pressing the Windows key, typing cmd, and pressing Enter.

Once the terminal is open, navigate to the folder where you want to work. If you have a folder called my_flask_project on your Desktop, you would type cd Desktop/my_flask_project and press Enter. The cd command means "change directory". If you are not sure what folder you are in, type pwd (on Mac or Linux) or cd (on Windows) to see your current location.

You do not have to be in a specific folder to install Flask globally, but organizing your work into a project folder makes it easier to keep track of your files later.

Run the pip install command

Type pip install flask and press Enter. Pip will connect to the internet, find the latest version of Flask, read it, and install it. You will see text scrolling in your terminal showing the read progress. This usually takes 30 seconds to two minutes depending on your internet speed.

When the installation finishes, you will see a line that says Successfully installed flask followed by a version number. If you see an error message instead, try python -m pip install flask on Windows, which sometimes works when the first command does not.

If you get a permission error on Mac or Linux, you may need to type sudo pip install flask instead, which asks for your computer password. Avoid using sudo if possible, because it installs Flask for all users on your computer rather than just your account.

Create a test file to confirm Flask works

Create a new file in your project folder called app.py. Open it in a text editor (Notepad on Windows, TextEdit on Mac, or any code editor) and type these lines exactly:

from flask import Flask app = Flask(__name__) @app.route('/') def hello():     return 'Flask is working' if __name__ == '__main__':     app.run(debug=True)

Save the file. Then go back to your terminal, make sure you are in the same folder as app.py, and type python app.py. You should see output that says something like Running on http://127.0.0.1:5000. Open your web browser and go to that address. If you see the text "Flask is working", the installation worked correctly.

To stop the Flask server, go back to your terminal and press Ctrl+C. This closes the connection and returns you to the command prompt.

Install Flask in a virtual environment for cleaner project management

A virtual environment is a separate folder on your computer where Python packages live for just one project. This keeps different projects from interfering with each other if they need different versions of the same library. Creating one is optional but recommended once you start working on multiple projects.

To create a virtual environment, open your terminal in your project folder and type python -m venv venv. This creates a folder called venv that holds all the packages for this project. Then set up it by typing source venv/bin/set up on Mac or Linux, or venv\Scripts\set up on Windows. You will see (venv) appear at the start of your terminal prompt, showing the virtual environment is active.

Now type pip install flask as before. Flask installs only inside this virtual environment, not on your whole computer. When you are done working, type deactivate to turn off the virtual environment. The next time you work on this project, set up it again with the same command you used before.

Troubleshooting common installation problems

If pip install flask fails with a network error, check that you are connected to the internet. If you are behind a corporate firewall or proxy, you may need to add extra settings to the pip command. Contact your network administrator for the correct proxy address, then type pip install --proxy [user:passwd@]proxy.server:port flask with your proxy details filled in.

If you see "permission denied" on Mac or Linux without using sudo, you may have a Python installation issue. Try python3 -m pip install flask instead, which explicitly uses Python 3. Some computers have both Python 2 and Python 3 installed, and the wrong one may be running by default.

If Flask installs but your test file does not run, make sure you saved the file with a .py extension. Also check that you are in the correct folder in your terminal by typing ls (Mac or Linux) or dir (Windows) to list the files. You should see app.py in the list.

Frequently Asked Questions

Do I need to install Flask separately for each project?

No, once Flask is installed on your computer, any Python file can use it. However, using a virtual environment for each project keeps your setup cleaner and prevents version conflicts. If you use virtual environments, you install Flask once per project inside that environment.

What is the difference between pip and pip3?

On computers with both Python 2 and Python 3, pip usually refers to Python 2 and pip3 refers to Python 3. Since Python 2 is no longer supported, use pip3 install flask if pip install flask does not work. You can also use python3 -m pip install flask, which is more reliable.

Can I use Flask on a Mac with Apple Silicon?

Yes, Flask works on Apple Silicon Macs. The installation process is identical. If you run into issues, make sure you installed Python from python.org rather than through Homebrew, as the official installer handles Apple Silicon better.

What if I want to uninstall Flask?

Type pip uninstall flask and press Enter. Pip will ask you to confirm, then remove Flask from your computer. If you used a virtual environment, deactivate it first, then uninstall. Uninstalling does not affect any Python files you created.

Is Flask the only Python web framework I can install this way?

No, pip can install thousands of Python libraries. Django, FastAPI, and Bottle are other web frameworks you can install with the same pip install command. The process is identical for any library available on PyPI, the Python Package Index.