ImportError: No module named flask_login even though I have it installed

Question:

I’m new at this and have no idea of what I’m doing wrong:
I have installed the flask_login module with

pip install flask_login

It apparently worked: if see it installed in c:users~pythonpython36-32libsite-packages

And when I use pip list, I can see it listed as Flask-Login (0.4.0)

Despite of this, when I try to run from flask_login import LoginManager, I’m getting ImportError: No module named flask_login.

What am I doing wrong?

Asked By: Original BBQ Sauce

||

Answers:

I figured out what was happening.

For some reason, Anaconda installed Python 2.7 in a path that was colliding with the one I use normally (w/ Python 3). Once I uninstalled Python 2.7, everything worked fine.

For some reason, only flask_login was being affected. My other flask_** libraries were working fine.

Answered By: Original BBQ Sauce

In case you are experiencing this in a Python environment with Apache2 and mod_wsgi: you have to restart the Apache2 server after installing new Python modules, as otherwise Apache2 will not “see” them even though the Python path is correct. So (assuming Debian / Ubuntu Linux):

service apache2 restart

Of course, this issue could happen with any module not being found, not just with flask_login. It just happened to me with flask_login, which is why I’m here …

Answered By: tanius

I had the same problem and was able to solve using sudo:

sudo pip install flask_login

I think import errors are so common in flask because flask users normally work in virtual environments. Running pip install inside a VE or outside leads to different installations in different paths and can cause confusion. sudo installation works globally and can be a solution if you don’t need a certain dependency in a specific VE.

Answered By: Lucas

I was using VS code. In the .venv there was another copy of flask_login so basically just check if another copy of flask_login exists within your lib

Answered By: Sean Umali
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.