`ModuleNotFoundError: 导入 psutil 模块时没有名为“psutil”的模块

时间:2021-06-11 14:12:45

标签: python virtualenv psutil

在我的烧瓶项目中,我使用 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)

但是当我执行我的烧瓶代码时,出现错误 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 执行我的烧瓶项目:

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

1 个答案:

答案 0 :(得分:0)

您的问题是 uwsgi 没有从通风口内部运行。为此,请使用以下命令运行应用程序:

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

查看类似问题 here 或文档 here