在Rasberry Pi重新启动时运行Python3模块 [英] Run Python3 module on Rasberry Pi reboot

查看:75
本文介绍了在Rasberry Pi重新启动时运行Python3模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经清理了Raspberry Pi(3 B +),并决定使用FastAPI制作家庭服务器.

I've dusted off my Raspberry Pi (3 B+) and decided to make a home server using FastAPI.

FastAPI需要运行Uvicorn,这是一个Python模块.运行它就像这样

FastAPI requires Uvicorn to run which is a Python module. Running it looks like so

python3 -m uvicorn --host 0.0.0.0 main:app

我希望每次打开Pi时都能运行此程序,因此crontab似乎是正确的解决方案.使用 sudo crontab -e ,我添加了行

I would like this to run every time the Pi is powered on, so crontab seemed like the right solution. using sudo crontab -e, I add the line

@reboot python3 -m uvicorn --host 0.0.0.0 main:app &

在线资源显示了如何执行脚本,您可以在其中指定绝对路径,但不能指定模块的路径

Online resources show how to execute a script where you can specify an absolute path, but not how for a module

我在做什么错了?

推荐答案

如RasPi文档中所述,设置

As mentioned in the RasPi docs, setting up a systemd service is an option as well.

此外,我们使用它来运行Flask网站以及其他后台服务.

Aside, we use this to run our Flask sites, as well as other background services.

这篇关于在Rasberry Pi重新启动时运行Python3模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆