小编doo*_*oon的帖子

python venv 的激活(activate_this.py)无法工作或抛出错误

Soo,我创建了一个小型 Flask 网站,我想将其部署在带有 Apache 2.4 的 Debian 10 服务器上

首先,我按照教程创建了 apache2 conf 文件和 .wsgi 文件。由于效果不佳,我收到错误“ModuleNotFoundError:没有名为“flask”的模块”,因此我设置了一个虚拟环境

python3 -m venv venv
Run Code Online (Sandbox Code Playgroud)

并将我的 .wsgi 更改为

#!/usr/bin/python3
import sys
import logging

activate_this = '/home/bot/Club-Manager/Webinterface/venv/bin/activate_this.py'

with open(activate_this) as file_:
        exec(file_.read(), dict(__file__=activate_this))

logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/home/bot/Club-Manager/Webinterface/")

import app as application

Run Code Online (Sandbox Code Playgroud)

现在我明白了

Failed to exec Python script file '/var/www/html/Webinterface/Webinterface.wsgi'
Exception occurred processing WSGI script '/var/www/html/Webinterface/Webinterface.wsgi'., file "/var/www/html/Webinterface/Webinterface.wsgi", line 8, in <module>, 
exec(file_.read(), dict(__file__=activate_this))
File "<string>", line 28, in <module>
AttributeError: 'str' object has no attribute 'decode'
Run Code Online (Sandbox Code Playgroud)

起初,“activate_this.py”对我来说并不存在,一些研究告诉我只需从我尝试过的 …

debian apache2 flask python-3.x debian-buster

5
推荐指数
1
解决办法
1721
查看次数

标签 统计

apache2 ×1

debian ×1

debian-buster ×1

flask ×1

python-3.x ×1