79

What's the easiest way to determine which version of Flask is installed?

15 Answers 15

98

As of flask 0.7 (June 28th, 2011), a __version__ attribute can be found on the flask module.

>> import flask
>> flask.__version__

Keep in mind that because prior to flask 0.7 there was no __version__ attribute, the preceding code will result in an attribute error on those older versions.

For versions older than flask 0.7, you might be able to determine it using pkg_resources as shown below:


>>> import pkg_resources
>>> pkg_resources.get_distribution('flask').version
'0.6.1'

This won't work 100% though. It depends on the user having the pkg_resources library installed (it might come by default with a Linux distribution's python installation, but since it's not part of the standard library you can't be positive), and also that the user installed flask in a way that pkg_resources can find it (for example, just copying the full flask source code into your directory puts it out of the range of pkg_resources).

24

More general way of doing it is :

pip freeze

It will list all installed python packages and their versions. If you want to see just flask then try :

pip freeze | grep flask
0
21

Via the python interpreter.

>> import flask
>> flask.__version__
'0.7.2'

If flask was installed via pip or easy_install, you can always use the 'pip freeze' command.

2
  • 1
    While that may work with newer versions of Flask, I just confirmed that flask.__version__ does not work with Flask 0.6.1. Sep 17, 2011 at 14:39
  • I upgraded Flask to 0.7.2 and confirmed that flask.__version__ does work. Time marches on. Sep 17, 2011 at 14:41
13

It's quite simple !

In your terminal:

pip freeze | grep Flask

The output should be something like this:

Output: Flask==0.12
9

Tested whith Flask 1.0.2

Inside the venv run flask --version

8

If someone is trying to determine flask version via Anaconda Command Prompt then just run the following command:

flask --version

Above command will give following output format:

Python 3.7.3
Flask 1.1.1
Werkzeug 0.15.4
3

using dpkg:

dpkg -l | grep flask

output:

ii  python-flask 0.8-1 all micro web framework based on Werkzeug, Jinja2 and good intentions 
0
3
>>> import flask
>>> flask.__version__        #(To find the version)
'1.0.2'
>>> print flask.__file__     #(To find out the path where it is installed)
/usr/local/rnt/lib/python2.7/site-packages/flask/__init__.pyc
2

If managing with pip can just use list command to see all the packages and versions

pip list

2

Update on Flask version 1.1.2

  1. If Flask not installed then go to the required conda environment and write:
$ conda activate "name of conda environment" //py3 in my case
(py3)$ conda install flask
  1. Post installation check the version with command:
(py3)$ flask --version

Please Note: __version__ is not an attribute of flask anymore for the latest versions and thus flask.__version__ would throw an error

Terminal Output

(py3) xxxxxx@xxxxx:~$ flask --version
Python 3.7.7
Flask 1.1.2
Werkzeug 1.0.1
0

just type pip show flask on cmd. You will get all the information about the installed flask. it will show you : name location version and many more

2
  • Doesn't this just show Pypi information? Not the current installed version? Or even if it is installed? Oct 5, 2022 at 18:34
  • then you write from flask import Flask in your IDE (pyCharm). If it does not show any red line or error this means it is installed Else it will show an error or red line whenever you import flask. You can also try this : python -m flask --version
    – NHKAIZEN
    Oct 6, 2022 at 12:20
0

Flask 3.0.0(released on 2023-09-30) deprecated the __version__ attribute and will be removed in Flask 3.1. The recommended way to access the version would be by using importlib.metadata.version API.

>>> import flask
>>> import importlib
>>> flask.__version__
<stdin>:1: DeprecationWarning: The '__version__' attribute is deprecated and will be removed in Flask 3.1. Use feature detection or 'importlib.metadata.version("flask")' instead.
'3.0.0'
>>> 
>>> importlib.metadata.version("flask")
'3.0.0'
>>>
-1

Just type:

python -m flask --version

Output:

Python 3.7.2 
Flask 1.1.1 
Werkzeug 0.16.0
-1

Type flask --version in your interpreter, for example: enter image description here

1
-2
pip show fastapi uvicorn

Output :

Name: fastapi
Version: 0.75.0
Summary: FastAPI framework, high performance, easy to learn, fast to code, ready for production
Home-page: https://github.com/tiangolo/fastapi
Author: Sebastián Ramírez
Author-email: [email protected]
License: None
Location: /home/mind/Desktop/FASTAPIBasic-/fastenv/lib/python3.8/site-packages
Requires: starlette, pydantic
Required-by: 
---
Name: uvicorn
Version: 0.17.6
Summary: The lightning-fast ASGI server.
Home-page: https://www.uvicorn.org/
Author: Tom Christie
Author-email: [email protected]
License: BSD
Location: /home/mind/Desktop/FASTAPIBasic-/fastenv/lib/python3.8/site-packages
Requires: h11, click, asgiref
Required-by: 
1
  • 1
    Question asked about Flask Oct 5, 2022 at 18:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.