说明
Flask:web框架
tornado:支持异步高并发
supervisro-win:监控web服务,死掉及重启
目录
1、安装虚拟环境
2、安装库文件(需在虚拟环境下)
2.1 安装 ultralytics(YoloV8)
2.2安装Torch
2.3安装flask 、tornado 、supervisor-win
3、打包成exe
4、部署
5、运行
1、安装虚拟环境
pip install virtualenv -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
virtualenv flask_env
2、安装库文件(需在虚拟环境下)
2.1 安装 ultralytics(YoloV8)
#先激活虚拟环境
activatr.bat
pip install ultralytics -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
2.2安装Torch
默认安装的是cpu版本的torch,如果要使用gpu版本的torch,需要卸载cpu版本在安装gpu版本
pip uninstall torch
pip uninstall torchvision
#需要保证安装顺序
pip install GPU版本torch
pip install GPU版本torchvision
2.3安装flask 、tornado 、supervisor-win
pip install flask -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
pip install tornado -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
pip install supervisor-win -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
pip install pyinstaller -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
3、打包成exe
pyinstaller F:PycharmpythonProject_flasktornado_service.py
报下面错误,不影响使用,等待即可
运行打包后的exe,如果无法正常启动web,报下面错误
解决办法:将libsite-packagesultralytics复制到同级目录下的Scriptsdisttornado_service中
或者 修改下面源文件
4、部署
[inet_http_server] ; inet (TCP) server disabled by default
port=127.0.0.1:9001 ; ip_address:port specifier, *:port for all iface
username=admin ; default is no username (open server)
password=123456 ; default is no password (open server)
[supervisord]
logfile=supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false ; (start in foreground if true;default false)
silent=false ; no logs to stdout if true; default false
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)
[program:theprogramname]
directory = F:\Pycharm\pythonProject_flask\
command = F:\Virtualenv_ENV\flask_env\Scripts\python.exe tornado_service.py
stdout_logfile=F:\Pycharm\pythonProject_flask\supervisord.log ; stdout log path, NONE for none; default AUTO
stderr_logfile=F:\Pycharm\pythonProject_flask\supervisord.err ; stderr log path, NONE for none; default AUTO
5、运行
supervisord.exe -c supervisor.conf