简体   繁体   中英

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

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\~\python\python36-32\lib\site-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?

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.

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 …

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM