如何通过脚本在虚拟环境中运行程序

编程入门 行业动态 更新时间:2024-10-27 22:20:57
本文介绍了如何通过脚本在虚拟环境中运行程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经在Raspberry Pi上设置了Google助手sdk,如下所示: developers.google/assistant/sdk/prototype/getting-started-pi-python/run-sample

现在为了重新运行助手,我已经计算出两个命令

$ source env/bin/activate

(env)$ google-assistant-demo

但是我想将此过程自动化为一个脚本,我可以从 rc.local 调用该脚本(后接& ),以使助手从以下位置启动启动.

但是如果我运行一个简单的脚本

#!/bin/bash源环境/bin/激活谷歌助手演示

该助手不在环境中运行我的环境路径是/home/pi/env/bin/activate 我怎么拥有它,以便脚本启动环境,然后在虚拟环境内 内运行助手?

最后,我使用以下方法:

以此为基础: youtu.be/ohUszBxuQA4?t=774 –感谢Eric Parisot

您将需要下载src文件,并将其内容提取到/home/pi/src/

但是有一些更改.

我没有以 sudo 的身份运行 gassist.sh ,因为它给了我以下错误:

OpenAlsaHandle PcmOpen:无此类文件或目录[7689:7702:ERROR:audio_input_processor.cc(756)]输入错误ON_MUTED_CHANGED:{‘is_muted’:False}ON_START_FINISHEDON_ASSISTANT_ERROR:{‘is_fatal’:正确}[7689:7704:ERROR:audio_input_processor.cc(756)]输入错误ON_ASSISTANT_ERROR:{‘is_fatal’:正确}

修复:请勿以 sudo

的身份运行

如果 gassist.sh 给出有关 RPi.GPIO 的错误,则需要执行 youtu.be/ohUszBxuQA4?t=580 :

$ cd/home/pi/env/bin$源激活(env)$ pip安装RPi.GPIO(env)$停用

然后我做了 sudo nano/etc/profile 并将其附加到末尾:

#Harvs于17年6月24日在这里如果pidof -x"gassist.sh">/dev/null;然后回声"回声"/etc/profile说:"回声"Google助手实例已在运行,将不会再次启动"回声"别的回显正在启动Google Assistant ..."回声如果您看到此消息,则可能在重启后几秒钟内就拥有了SSH"/home/pi/src/gassist.sh&科幻

现在,它可以在虚拟环境中完美运行:)

解决方案

最后,我使用了以下方法:

以此为基础: youtu.be/ohUszBxuQA4?t=774

但是有一些更改.

您将需要下载src文件,并将其内容提取到/home/pi/src/

我没有以 sudo 的身份运行 gassist.sh ,因为它给了我以下错误:

OpenAlsaHandle PcmOpen:无此类文件或目录[7689:7702:ERROR:audio_input_processor.cc(756)]输入错误ON_MUTED_CHANGED:{‘is_muted’:False}ON_START_FINISHEDON_ASSISTANT_ERROR:{‘is_fatal’:正确}[7689:7704:ERROR:audio_input_processor.cc(756)]输入错误ON_ASSISTANT_ERROR:{‘is_fatal’:正确}

修复:请勿以sudo身份运行

如果 gassist.sh 给出有关 RPi.GPIO 的错误,则需要执行 youtu.be/ohUszBxuQA4?t=580 :

$ cd/home/pi/env/bin$源激活(env)$ pip安装RPi.GPIO(env)$停用

然后我做了 sudo nano/etc/profile 并将其附加到末尾:

#Harvs于17年6月24日在这里如果pidof -x"gassist.sh">/dev/null;然后回声"回声"/etc/profile说:"回声"Google助手实例已在运行,将不会再次启动"回声"别的回显正在启动Google Assistant ..."回声如果您看到此消息,则可能在重启后几秒钟内就拥有了SSH"/home/pi/src/gassist.sh&科幻

现在,它可以在虚拟环境中完美运行,并且可以引导至CLI模式!:)

I have set up the google assistant sdk on my Raspberry Pi as shown here: developers.google/assistant/sdk/prototype/getting-started-pi-python/run-sample

Now in order to re-run the assistant I have worked out the two commands are

$ source env/bin/activate

and

(env) $ google-assistant-demo

however I want to automate this process into a script that I can call from rc.local (followed by an &) in order to make the assistant boot from start up.

However if I run a simple script

#!/bin/bash source env/bin/activate google-assistant-demo

the assistant does not run inside the environment my environment path is /home/pi/env/bin/activate How can I have it so the script starts the environment and then runs the assistant inside the virtual environment?

EDIT: In the end I went with the following method:

using this as a base : youtu.be/ohUszBxuQA4?t=774 – thanks to Eric Parisot

You will need to download the src file he uses and extract its contents into /home/pi/src/

However with a few changes.

I did not run gassist.sh as sudo, as it gave me the following error:

OpenAlsaHandle PcmOpen: No such file or directory [7689:7702:ERROR:audio_input_processor.cc(756)] Input error ON_MUTED_CHANGED: {‘is_muted’: False} ON_START_FINISHED ON_ASSISTANT_ERROR: {‘is_fatal’: True} [7689:7704:ERROR:audio_input_processor.cc(756)] Input error ON_ASSISTANT_ERROR: {‘is_fatal’: True}

Fix: DO NOT run as sudo

If gassist.sh gives an error about RPi.GPIO you need to do youtu.be/ohUszBxuQA4?t=580:

$ cd /home/pi/env/bin $ source activate (env) $ pip install RPi.GPIO (env) $ deactivate

And then I did sudo nano /etc/profile and the appended this to the end:

#Harvs was here on 24/06/17 if pidof -x "gassist.sh" >/dev/null; then echo "" echo "/etc/profile says:" echo "An instance of Google Assistant is already running, will not start again" echo "" else echo "Starting Google Assistant..." echo "If you are seeing this, perhaps you have SSH within seconds of reboot" /home/pi/src/gassist.sh & fi

And now it works perfectly, and inside the virtual enviroment :)

解决方案

In the end I went with the following method:

using this as a base : youtu.be/ohUszBxuQA4?t=774 – thanks to Eric Parisot

However with a few changes.

You will need to download the src file he uses and extract its contents into /home/pi/src/

I did not run gassist.sh as sudo, as it gave me the following error:

OpenAlsaHandle PcmOpen: No such file or directory [7689:7702:ERROR:audio_input_processor.cc(756)] Input error ON_MUTED_CHANGED: {‘is_muted’: False} ON_START_FINISHED ON_ASSISTANT_ERROR: {‘is_fatal’: True} [7689:7704:ERROR:audio_input_processor.cc(756)] Input error ON_ASSISTANT_ERROR: {‘is_fatal’: True}

Fix: DO NOT run as sudo

If gassist.sh gives an error about RPi.GPIO you need to do youtu.be/ohUszBxuQA4?t=580:

$ cd /home/pi/env/bin $ source activate (env) $ pip install RPi.GPIO (env) $ deactivate

And then I did sudo nano /etc/profile and the appended this to the end:

#Harvs was here on 24/06/17 if pidof -x "gassist.sh" >/dev/null; then echo "" echo "/etc/profile says:" echo "An instance of Google Assistant is already running, will not start again" echo "" else echo "Starting Google Assistant..." echo "If you are seeing this, perhaps you have SSH within seconds of reboot" /home/pi/src/gassist.sh & fi

And now it works perfectly, and inside the virtual enviroment, and in boot to CLI mode! :)

更多推荐

如何通过脚本在虚拟环境中运行程序

本文发布于:2023-11-24 03:01:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623735.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   环境   程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!