I am trying to use flask_login from the flask-security-too package, but I cannot seem to import it.
Looking at the documentation, the function does not seem to be deprecated or anything.
I tried different arrangements of package and sub-package to import it, but no luck
>>> import flask_security
>>> from flask_security.utils import login_user
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'flask_security.utils'
>>> from flask_security import login_user
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'login_user' from 'flask_security' (unknown location)
>>> from flask_security import utils
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'utils' from 'flask_security' (unknown location)
>>> flask_security.login_user
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'flask_security' has no attribute 'login_user'
And so that you can see what I have installed, here is the output of pip list
:
Package Version
------------------- ------------
Babel 2.13.1
bcrypt 4.0.1
blinker 1.6.3
boto3 1.28.75
botocore 1.31.75
cffi 1.16.0
click 8.1.7
cryptography 41.0.5
dnspython 2.4.2
email-validator 2.1.0.post1
Flask 3.0.0
Flask-Assets 2.1.0
flask-babel 4.0.0
Flask-BabelEx 0.9.4
Flask-Login 0.6.3
Flask-Mail 0.9.1
Flask-MDE 1.2.1
Flask-Principal 0.4.0
Flask-Security-Too 5.3.2
Flask-SQLAlchemy 3.1.1
Flask-Table 0.5.0
Flask-WTF 1.2.1
greenlet 3.0.1
gunicorn 21.2.0
idna 3.4
importlib-metadata 6.8.0
importlib-resources 6.1.0
itsdangerous 2.1.2
Jinja2 3.1.2
jmespath 1.0.1
markup 0.2
MarkupSafe 2.1.3
numpy 1.26.1
packaging 23.2
pandas 2.1.2
paramiko 3.3.1
passlib 1.7.4
pip 23.3.1
psycopg2-binary 2.9.9
pycparser 2.21
PyNaCl 1.5.0
python-dateutil 2.8.2
python-decouple 3.8
python-dotenv 1.0.0
pytz 2023.3.post1
s3transfer 0.7.0
setuptools 53.0.0
six 1.16.0
speaklater 1.3
SQLAlchemy 2.0.22
sqlalchemy-json 0.7.0
typing_extensions 4.8.0
tzdata 2023.3
urllib3 1.26.18
webassets 2.0
Werkzeug 3.0.1
WTForms 3.1.1
zipp 3.17.0
Am I missing something super obvious, or has something changed? I'm certain I have previously just done from flask_security import login_user
without issue.
Edit: information requested by @john_gordon:
NameError: name 'flask_security' is not defined
>>> import flask_security
>>> print(flask_security.__file__)
None
>>> print(dir(flask_security))
['__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
>>> print(flask_security.__path__)
_NamespacePath(['/home/datman/flask_venv/lib64/python3.9/site-packages/flask_security', '/home/datman/flask_venv/lib/python3.9/site-packages/flask_security'])
✗ pip show Flask-Security-Too
Name: Flask-Security-Too
Version: 5.3.2
Summary: Quickly add security features to your Flask application.
Home-page:
Author: Matt Wright
Author-email: Chris Wagner <[email protected]>
License:
Location: /home/datman/flask_venv/lib/python3.9/site-packages
Requires: email-validator, Flask, Flask-Login, Flask-Principal, Flask-WTF, importlib-resources, markupsafe, passlib, wtforms
Required-by:
Edit: Installed on a totally fresh venv with nothing else, I am able to import as expected. I will install my requirements one-by-one and see if and when the problem re-emerges.
Edit: So I have reinstalled all my packages and all seems well. The only thing I can think of is that maybe when I initially installed packages from requirements.txt
it caused different versions of packages to be pulled in and thus I ended up with a dependency issue. I had manually uninstalled flask-security
and replaced it with flask-security-too
, maybe that caused problems that pip was not able to detect/resolve.