`ModuleNotFoundError: No module named 'psutil'` when import psutil module

`ModuleNotFoundError: No module named 'psutil'` when import psutil module

在我的flask项目中,我使用uwsgi运行它

在我的项目中有 import psutil.

当然我在我的 venv 中安装了最新的 psutil:

(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)

但是当我执行我的 flask 代码时,出现错误 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

我的pip3pip都来自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

我的python3路径:

(venv) [root@7338cdd80407 ssl-node]# which python3
/www/wwwroot/ssl-node/venv/bin/python3

我使用uwsgi -d --ini uwsgi_prod.ini执行我的flask项目:

uwsgi_prod.ini内容:

[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

你看到从 manager.py 执行: 内容:

#-*- 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")

你的问题是 uwsgi 不是 运行 来自通风口。为此 运行 应用程序:

uwsgi -d --ini uwsgi_prod.ini -H /www/wwwroot/ssl-node/venv/bin/python3

查看类似问题here or the documentation here