英文:
No module named 'flask' in virtualenv
问题
I was running pgAdmin4
in Centos 8 with no problems. I upgraded to pgAdmin4 7.11
and now it no longer works. This is the error:
ModuleNotFoundError: No module named 'flask'
Flask is installed in the virtualenv:
# pwd
/usr/pgadmin4/venv/lib/python/site-packages
# ll -d flask*
drwxrwxr-x. 3 root root 4096 May 29 12:14 flask
drwxrwxr-x. 2 root root 46 May 29 12:14 flask_babel
drwxrwxr-x. 2 root root 98 May 29 12:14 flask_babel-3.1.0.dist-info
drwxrwxr-x. 2 root root 69 May 29 12:14 flask_compress
drwxrwxr-x. 2 root root 43 May 29 12:14 flask_gravatar
drwxrwxr-x. 2 root root 159 May 29 12:14 flask_login
-rw-rw-r--. 1 root root 17950 May 3 11:10 flask_mail.py
drwxrwxr-x. 3 root root 56 May 29 12:14 flask_migrate
drwxrwxr-x. 2 root root 44 May 29 12:14 flask_paranoid
-rw-rw-r--. 1 root root 13860 May 3 11:10 flask_principal.py
drwxrwxr-x. 6 root root 4096 May 29 12:14 flask_security
drwxrwxr-x. 2 root root 67 May 29 12:14 flask_socketio
drwxrwxr-x. 2 root root 4096 May 29 12:14 flask_sqlalchemy
drwxrwxr-x. 3 root root 120 May 29 12:14 flask_wtf
# ll -d Flask*
drwxrwxr-x. 2 root root 147 May 29 12:14 Flask-2.2.5.dist-info
drwxrwxr-x. 2 root root 123 May 29 12:14 Flask_Compress-1.13.dist-info
drwxrwxr-x. 2 root root 148 May 29 12:14 Flask_Gravatar-0.5.0.dist-info
drwxrwxr-x. 2 root root 119 May 29 12:14 Flask_Login-0.6.2.dist-info
drwxrwxr-x. 2 root root 119 May 29 12:14 Flask_Mail-0.9.1.dist-info
drwxrwxr-x. 2 root root 119 May 29 12:14 Flask_Migrate-4.0.4.dist-info
drwxrwxr-x. 2 root root 119 May 29 12:14 Flask_Paranoid-0.3.0.dist-info
drwxrwxr-x. 2 root root 87 May 29 12:14 Flask_Principal-0.4.0.dist-info
drwxrwxr-x. 2 root root 134 May 29 12:14 Flask_Security_Too-5.1.2.dist-info
drwxrwxr-x. 2 root root 119 May 29 12:14 Flask_SocketIO-5.3.4.dist-info
drwxrwxr-x. 3 root root 99 May 29 12:14 Flask_SQLAlchemy-3.0.3.dist-info
drwxrwxr-x. 2 root root 123 May 29 12:14 Flask_WTF-1.1.1.dist-info
$PYTHONPATH
is empty:
# source bin/activate
(venv) [root@ck venv]# echo $PYTHONPATH
The virtualenv is using its own python as expected:
(venv) [root@ck venv]# which python
/usr/pgadmin4/venv/bin/python
If I import flask
from the virtualenv python interactive it works:
(venv) [root@ck venv]# python
Python 3.9.16 (main, Jan 17 2023, 18:53:15)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
>>>
英文:
I was running pgAdmin4
in Centos 8 with no problems. I upgraded to pgAdmin4 7.11
and now it no longer works. This is the error:
ModuleNotFoundError: No module named 'flask'
Flask is installed in the virtualenv:
# pwd
/usr/pgadmin4/venv/lib/python/site-packages
# ll -d flask*
drwxrwxr-x. 3 root root 4096 May 29 12:14 flask
drwxrwxr-x. 2 root root 46 May 29 12:14 flask_babel
drwxrwxr-x. 2 root root 98 May 29 12:14 flask_babel-3.1.0.dist-info
drwxrwxr-x. 2 root root 69 May 29 12:14 flask_compress
drwxrwxr-x. 2 root root 43 May 29 12:14 flask_gravatar
drwxrwxr-x. 2 root root 159 May 29 12:14 flask_login
-rw-rw-r--. 1 root root 17950 May 3 11:10 flask_mail.py
drwxrwxr-x. 3 root root 56 May 29 12:14 flask_migrate
drwxrwxr-x. 2 root root 44 May 29 12:14 flask_paranoid
-rw-rw-r--. 1 root root 13860 May 3 11:10 flask_principal.py
drwxrwxr-x. 6 root root 4096 May 29 12:14 flask_security
drwxrwxr-x. 2 root root 67 May 29 12:14 flask_socketio
drwxrwxr-x. 2 root root 4096 May 29 12:14 flask_sqlalchemy
drwxrwxr-x. 3 root root 120 May 29 12:14 flask_wtf
# ll -d Flask*
drwxrwxr-x. 2 root root 147 May 29 12:14 Flask-2.2.5.dist-info
drwxrwxr-x. 2 root root 123 May 29 12:14 Flask_Compress-1.13.dist-info
drwxrwxr-x. 2 root root 148 May 29 12:14 Flask_Gravatar-0.5.0.dist-info
drwxrwxr-x. 2 root root 119 May 29 12:14 Flask_Login-0.6.2.dist-info
drwxrwxr-x. 2 root root 119 May 29 12:14 Flask_Mail-0.9.1.dist-info
drwxrwxr-x. 2 root root 119 May 29 12:14 Flask_Migrate-4.0.4.dist-info
drwxrwxr-x. 2 root root 119 May 29 12:14 Flask_Paranoid-0.3.0.dist-info
drwxrwxr-x. 2 root root 87 May 29 12:14 Flask_Principal-0.4.0.dist-info
drwxrwxr-x. 2 root root 134 May 29 12:14 Flask_Security_Too-5.1.2.dist-info
drwxrwxr-x. 2 root root 119 May 29 12:14 Flask_SocketIO-5.3.4.dist-info
drwxrwxr-x. 3 root root 99 May 29 12:14 Flask_SQLAlchemy-3.0.3.dist-info
drwxrwxr-x. 2 root root 123 May 29 12:14 Flask_WTF-1.1.1.dist-info
$PYTHONPATH
is empty:
# source bin/activate
(venv) [root@ck venv]# echo $PYTHONPATH
The virtualenv is using its own python as expected:
(venv) [root@ck venv]# which python
/usr/pgadmin4/venv/bin/python
If I import flask
from the virtualenv python interactive it works:
(venv) [root@ck venv]# python
Python 3.9.16 (main, Jan 17 2023, 18:53:15)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
>>>
答案1
得分: 1
我找到了问题。wsgi版本是使用与虚拟环境中不同的早期Python版本构建的。我卸载了wsgi并安装了一个与虚拟环境中相同Python版本的版本,现在它可以正常工作。
英文:
I found the problem. The wsgi version was built with an earlier Python version different from the one in the virtualenv. I removed wsgi and installed one with the same Python version in the virtualenv and now it works.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论