dusty-nv / jetson-inference

Hello AI World guide to deploying deep-learning inference networks and deep vision primitives with TensorRT and NVIDIA Jetson.
https://developer.nvidia.com/embedded/twodaystoademo
MIT License
7.84k stars 2.98k forks source link

Can't get Jetson imports to run from script file #1465

Closed KCHBloem closed 2 years ago

KCHBloem commented 2 years ago

Hello, I am trying to run a .sh file to launch my python program. Which looks something like this:

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

And it runs the python program up until it gets to the part where it imports jetson.inference and jetson.utils when it gets to that point it just closes the terminal. When I run python3 detect.py from the terminal manually it works just fine, my program executes normally. It just doesn't work from the .sh file. I don't know what exactly it could be related to, maybe you can help me.

dusty-nv commented 2 years ago

Hi @Unweptpit, not sure what would be causing this - are you double-clicking this shell script, or running it from terminal?

Is there any output from the program?

What happens if you replace the first line with #!/usr/bin/env bash ?

KCHBloem commented 2 years ago

Thanks for taking the time to reply. The situation is as follows, I have a touchscreen attached to a jetson nano. I would like to control everything through the touchscreen (clicking with a mouse). So I've made a .desktop application which runs the .sh script when it is double-clicked. The .sh script then attempts to launch the python program. Which is where the problem occurs. There is no output whatsoever in the terminal, it just launches an empty terminal and closes it immediately. (apart from the first print statement) I've tried your suggestion, it gave me this error. Screenshot from 2022-08-08 19-15-58

Also, there is more happening after the imports. It doesn't reach the end of the program and closes the terminal because of that

dusty-nv commented 2 years ago

What if you use xterm -hold -e "python3 detect.py" in your script instead?

or gnome-terminal or lxterminal, ect

https://stackoverflow.com/a/23105350 https://askubuntu.com/questions/394897/double-click-on-sh-file-to-open-terminal-and-execute-series-of-commands-in-it

KCHBloem commented 2 years ago

xterm -hold -e results in this, terminal stays open but does nothing. image gnome-terminal opens another terminal but just closes it immediately after printing this gets printed, no other output except for stating that -e is depreciated. lxterminal doesn't launch anything

dusty-nv commented 2 years ago

Hmm okay - sorry, I don't know what is happening

Can you try making a .desktop launcher like shown here: https://stackoverflow.com/a/23105350

KCHBloem commented 2 years ago

Thank you for giving me suggestions anyway. I was actually already using a .desktop application to launch the script. I've tried your suggestion and edited the .desktop application to the following.

[Desktop Entry]
Name=Velotech
Comment=Run the script in a Terminal window
Exec=bash -c 'cd /home/velotech/workspace && python3 detect.py'
Type=Application
Terminal=true
Icon=utilities-terminal
NoDisplay=true

This results in the same behavior as in the beginning, a terminal opens, it prints this gets printed and then closes. Some things I've noticed though, the program runs fine when I use python3 detect.py from the terminal myself but it also runs fine when I use ./start.sh from the terminal. So the only time it doesn't work is when I double click the .desktop application to launch the script.

*Edit Apparently it is possible to make .sh scripts double clickable as well, so I've done exactly that but that also doesn't work. Just opens and closes a terminal. So odd that it works when I execute it through terminal but not when I double click it..

*Edit 2 2 more things I've tried:

  1. tried to launch this python program by double clicking the .sh script hello.py

    print('Enter your name:')
    x = input()
    print('Hello, ' + x)

    This program works by double clicking.

  2. Copied the my-recognition.py from jetson-inference and tried to run the .sh file by double clicking. Same behavior as with my own .py program. Opens a terminal does everything up until the import jetson.inference and import jetson.utils and then exits.

Have you tried reproducing this issue? perhaps it has to do with my jetson nano/ubuntu

KCHBloem commented 2 years ago

Today I did a complete re-install on my Jetson Nano and did a fresh install of jetson-inference. When I ran the example it threw a warning saying jetson.utils is precated and to use jetson_utils instead. After doing that I was able to run it from a .sh file and by double clicking the .sh file