[英]Why does my python program not run when I double click the .sh file
OS: Ubuntu操作系统:Ubuntu
Device: Jetson Nano developer kit 2GB设备:Jetson Nano 开发者套件 2GB
I've got a python program that I want to launch by double clicking.我有一个 python 程序,我想通过双击启动它。 The reason for this is because I want to control the entire device with just a touchscreen.
这样做的原因是因为我想只用一个触摸屏来控制整个设备。 I've written a
.sh
file to launch the python program however when I double click it a terminal opens and immediately closes, the same thing happens when I run the .sh
file manually through the terminal.我编写了一个
.sh
文件来启动 python 程序,但是当我双击它时,终端会打开并立即关闭,当我通过终端手动运行.sh
文件时也会发生同样的事情。
.sh
file: .sh
文件:
#!/usr/bin/env bash
echo "Starting"
sleep 1
cd /home/velotech/workspace
python3 detect.py
The weird thing is that when I run the command python3 detect.py
manually from the terminal the program runs just fine.奇怪的是,当我从终端手动运行命令
python3 detect.py
时,程序运行得很好。 Things I've tried:我尝试过的事情:
hello.py
program, this one works both by double clicking the .sh
file and through terminal so I don't think it has to do with my.sh filehello.py
程序,这个程序可以通过双击.sh
文件和终端来工作,所以我认为它与 my.sh 文件无关print('Enter your name:')
x = input()
print('Hello, ' + x)
Jetson.inference
and jetson.utils
.Jetson.inference
和jetson.utils
后程序停止工作。 A snippet of the code from detect.py
:detect.py
的代码片段:#!/usr/bin/python3
import serial
from gpsZEDF9P.ublox_gps import UbloxGps
import time
import threading as thread
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QMessageBox, QLabel, QVBoxLayout, QHBoxLayout, QFrame, QSizePolicy, QComboBox
from PyQt5 import QtCore
import sys
print("this gets printed")
import jetson.utils
import jetson.inference
print("This does not")
... rest of the code
When I run this from the terminal it works but when I run it through the .sh
file it closes the terminal after the first print statement.当我从终端运行它时,它可以工作,但是当我通过
.sh
文件运行它时,它会在第一个打印语句之后关闭终端。 So my question is, what could this be?所以我的问题是,这可能是什么?
You are running:你在跑步:
python3 detect.py
Debug by running this instead:通过运行它来调试:
python3 -m site
sleep 30
Verify that the identical $PYTHONPATH
/ sys.path
is used in both your terminal and double-click environments.验证在您的终端和双击环境中是否使用了相同的
$PYTHONPATH
/ sys.path
。 Take care to export
a new value for that env var if you notice a mismatch, or use conda activate myproject
or the corresponding venv
command, so the same libraries are available in both environments.如果您发现不匹配,请注意为该环境变量
export
一个新值,或者使用conda activate myproject
或相应的venv
命令,以便在两种环境中都可以使用相同的库。
In case anyone else comes across this, after I updated the libraries Jetson Utils and Jetson Inference it threw a warning saying jetson.utils and jetson.inference were deprecated and to use jetson_utils and jetson_inference instead.万一其他人遇到这种情况,在我更新库 Jetson Utils 和 Jetson Inference 后,它会发出警告,说不推荐使用 jetson.utils 和 jetson.inference 并改用 jetson_utils 和 jetson_inference。 After doing so I was able to run the program from a.sh file and by double clicking it
这样做之后,我能够从 a.sh 文件运行程序并双击它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.