简体   繁体   English

为什么我的python程序双击.sh文件不运行

[英]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:我尝试过的事情:

  1. Made a simple 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 file制作了一个简单的hello.py程序,这个程序可以通过双击.sh文件和终端来工作,所以我认为它与 my.sh 文件无关
print('Enter your name:')
x = input()
print('Hello, ' + x)
  1. Added print statements in my python program, I've found out that the program stops working after I import two jetson libraries Jetson.inference and jetson.utils .在我的 python 程序中添加了打印语句,我发现在我导入两个 jetson 库Jetson.inferencejetson.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.

相关问题 为什么我运行我的Python程序时得到“sh:1:语法错误:未终止的引用字符串”? - Why I got “sh: 1: Syntax error: Unterminated quoted string” when I run my Python program? 为什么我的代码可以在python shell中工作,但是当我双击py文件时却不能工作 - Why does my code work in python shell but not when I double click the py file 通过双击执行时我的Python程序关闭 - my Python program shut down when i executing by double click 为什么我的代码可以在IDLE中工作,但在保存文件并双击文件后却不能工作? - why does my code works in IDLE but not when I save the file and double click the file? 为什么我的代码在IDLE中工作,但在保存文件并双击文件后却无法工作 - Why does my code work in IDLE but not when I save the file and double click the file 为什么python,当我运行我的程序时出现错误'预期缩进块? - Why does python, when I run my program comes up with the error 'expected an indented block? 为什么我的程序在运行时没有响应 - Why does my program not respond when I run it 为什么当我运行 sh 'python --version' 时 Jenkins 返回并退出代码 127? - Why does Jenkins returns and exit code 127 when I run sh 'python --version'? 为什么我的 pyinstaller python 程序在双击时崩溃,而不是在 cmd 运行时崩溃 - Why my pyinstaller python program crashes when double-clicked and not when cmd run 当我使用Process.Start运行python程序时,我的python程序中的日志不起作用吗? - When I run a python program using Process.Start the log in my python program does not work?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM