Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ModuleNotFoundError: No module named 'flask_session'

Tags:

python

flask

I have a simple python file that I am trying to set up to utilize sessions, when i run the file I am receiving the error below:

ModuleNotFoundError: No module named 'flask_session'

I believe I am importing the module properly, is there anything else that I can check to set this up properly?

from flask import Flask, render_template, request, session
from flask_session import Session

app = Flask(__name__)

app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"

Session(app)

@app.route("/", methods=["GET", "POST"])
def index():
    if session.get("notes") is None:
        session["notes"] = []

    if request.method == "POST":
        note = request.form.get("note")
        session["notes"].append(note)

    return render_template("index.html", notes=notes)

Here is the traceback ( most recent call last )

File "c:\python37\lib\site-packages\flask\cli.py", line 325, in __call__
Open an interactive python shell in this frameself._flush_bg_loading_exception()

File "c:\python37\lib\site-packages\flask\cli.py", line 313, in _flush_bg_loading_exception
reraise(*exc_info)

File "c:\python37\lib\site-packages\flask\_compat.py", line 35, in reraise
raise value

File "c:\python37\lib\site-packages\flask\cli.py", line 302, in _load_app
self._load_unlocked()

File "c:\python37\lib\site-packages\flask\cli.py", line 317, in _load_unlocked
self._app = rv = self.loader()

File "c:\python37\lib\site-packages\flask\cli.py", line 372, in load_app
app = locate_app(self, import_name, name)

File "c:\python37\lib\site-packages\flask\cli.py", line 242, in locate_app
'\n\n{tb}'.format(name=module_name, tb=traceback.format_exc())
like image 337
chris Avatar asked Jul 12 '18 19:07

chris


People also ask

How would you upgrade a package named flask?

X version then all you need to do is just install flas module with this command: pip3 install flask. Second solution is First of all just create a new virtualenv with this command: virtualenv flask Then open it with: cd flask. Now you have to activate the virtualenv with this command: source bin/activate.


1 Answers

I've first encountered this problem while doing Harvard's CS50x class. I'm using Linux and I've been using Python3, as it turns out I've installed Flask-Session for Python2. I don't know whether it also applies to Mac but I used the following instead:

$ pip3 install flask-session

Then you can check whether it's installed with pip's freeze command. After doing this my pylint in VSCode no longer gave an error.

like image 92
Gusti Scarlett Halima Avatar answered Oct 12 '22 23:10

Gusti Scarlett Halima