繁体   English   中英

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

[英]Why does my python program not run when I double click the .sh file

操作系统:Ubuntu

设备:Jetson Nano 开发者套件 2GB

我有一个 python 程序,我想通过双击启动它。 这样做的原因是因为我想只用一个触摸屏来控制整个设备。 我编写了一个.sh文件来启动 python 程序,但是当我双击它时,终端会打开并立即关闭,当我通过终端手动运行.sh文件时也会发生同样的事情。

.sh文件:

#!/usr/bin/env bash
echo "Starting"
sleep 1
cd /home/velotech/workspace
python3 detect.py

奇怪的是,当我从终端手动运行命令python3 detect.py时,程序运行得很好。 我尝试过的事情:

  1. 制作了一个简单的hello.py程序,这个程序可以通过双击.sh文件和终端来工作,所以我认为它与 my.sh 文件无关
print('Enter your name:')
x = input()
print('Hello, ' + x)
  1. 在我的 python 程序中添加了打印语句,我发现在我导入两个 jetson 库Jetson.inferencejetson.utils后程序停止工作。 来自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

当我从终端运行它时,它可以工作,但是当我通过.sh文件运行它时,它会在第一个打印语句之后关闭终端。 所以我的问题是,这可能是什么?

你在跑步:

python3 detect.py

通过运行它来调试:

python3 -m site
sleep 30

验证在您的终端和双击环境中是否使用了相同的$PYTHONPATH / sys.path 如果您发现不匹配,请注意为该环境变量export一个新值,或者使用conda activate myproject或相应的venv命令,以便在两种环境中都可以使用相同的库。

万一其他人遇到这种情况,在我更新库 Jetson Utils 和 Jetson Inference 后,它会发出警告,说不推荐使用 jetson.utils 和 jetson.inference 并改用 jetson_utils 和 jetson_inference。 这样做之后,我能够从 a.sh 文件运行程序并双击它

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM