Issue
In my flask project, I use uwsgi
run it.
in my project there has import psutil
.
off course I installed latest psutil in my venv:
(venv) [root@7338cdd80407 ssl-node]# pip3 install --upgrade psutil
Requirement already satisfied: psutil in /www/wwwroot/ssl-node/venv/lib64/python3.6/site-packages (5.8.0)
but when I execute my flask code, there get error ModuleNotFoundError: No module named 'psutil'
:
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 703600 bytes (687 KB) for 8 cores
*** Operational MODE: preforking+threaded ***
added /www/wwwroot/ssl-node/ssl-node/ to pythonpath.
Traceback (most recent call last):
File "/www/wwwroot/ssl-node/ssl-node/manager.py", line 9, in <module>
from api import app
File "/www/wwwroot/ssl-node/ssl-node/api.py", line 5, in <module>
from utils import utils, util_check_pem_key_cert
File "/www/wwwroot/ssl-node/ssl-node/utils/utils.py", line 8, in <module>
from .util_process import (
File "/www/wwwroot/ssl-node/ssl-node/utils/util_process.py", line 6, in <module>
import psutil
ModuleNotFoundError: No module named 'psutil'
unable to load app 0 (mountpoint='') (callable not found or import error)
EDIT-01
my pip3
and pip
both comes from venv
:
(venv) [root@7338cdd80407 ssl-node]# which pip3
/www/wwwroot/ssl-node/venv/bin/pip3
(venv) [root@7338cdd80407 ssl-node]# which pip
/www/wwwroot/ssl-node/venv/bin/pip
EDIT-02
My python3 path:
(venv) [root@7338cdd80407 ssl-node]# which python3
/www/wwwroot/ssl-node/venv/bin/python3
I use uwsgi -d --ini uwsgi_prod.ini
execute my flask project:
uwsgi_prod.ini
content:
[uwsgi]
http=0.0.0.0:5000
processes=4
threads=2
master=true
pythonpath=/www/wwwroot/ssl-node/ssl-node
module=manager
callable=app
memory-report=true
buffer-size=32768
static-map=/static=/www/wwwroot/ssl-node/ssl-node/static
daemonize=/www/wwwroot/ssl-node/ssl-node/log/uwsgi.log
you see there execute from manager.py
:
the content of it:
#-*- coding:utf-8 -*-
# Author: jack
import sys,os
path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(path)
from api import app
if __name__ == "__main__":
app.run("0.0.0.0")
Solution
Your problem is that uwsgi
is not being run from inside the vent. To do so run the application with:
uwsgi -d --ini uwsgi_prod.ini -H /www/wwwroot/ssl-node/venv/bin/python3
See a similar issue here or the documentation here
Answered By - Matteo Zanoni Answer Checked By - Candace Johnson (WPSolving Volunteer)