Use Pyinstaller to create executable file for deepstream's Python samples

Hi, I am using pyinstaller to make my Python based deepstream application executable (I am using jetson nano) . I have modified one of the Python samples of deepstream 5 to create my own application. Needless to say that pyinstaller can also create executable files for ubuntu based ARM architectures.

I run “pyinstaller my_application.py“,and it creates a dist folder, in which You can find several files(like.so files), as well as the executable file named “my_application”.

When I run "my_applicatin“, it runs well and creates all gstreamer plugins except the following plugins:

Unable to create NvStreamMux
Unable to create pgie
Unable to create nvosd

Seems like this might be a Path Issue, could You please help?

Can you provide the setup info as below?

• GPU & Jetson
• DeepStream 5.0
• TensorRT 7.1.3
• NVIDIA GPU Driver Version: 440.100
• Issue Type: Discussion

And, can you check if nvstreammux exists with command - “$ gst-inspect-1.0 nvstreammux” ,ad las other plugins ?

Seems like this might be a Path Issue

Can you share mo info about how got this conclusion?

1 Like

Is this still an issue to support? Any result can be shared?

Hello again, and sorry for the late response.

the issue is solved now and I can successfully create an executable file for my python based deepstream application (pedestrian detector built upon the deepstream-test2 python sample), using pyinstaller. good news is: it seems to have gathered all it needs to independently run the executable file (i.e. if you have a new fresh jetson nano (in my case) with the same L4T installed on it, you can simply copy paste the folder containing the executable file and other libraries to any path in your new jetson nano, and it should work fine, even if you don’t have deepstream, python, etc. installed on it.)

I solved the issue of pyinstaller not being able to find nvstreammux, pgie, osd, etc. by explicitly adding the path to their .so files to my pyinstaller command. here is what I did:

pyinstaller --add-binary ‘/usr/lib/aarch64-linux-gnu/gstreamer-1.0/deepstream/*.so:.’ --add-data /opt/nvidia/deepstream/deepstream-5.0/sources/deepstream_python_apps/apps/common:common deepstream_test_2.py

after running this, a “dist” folder is created, where you can find your executable file as deepstream_test_2.
then copy paste the config files and tensorrt files of your primary and secondary detectors to the same folder.

then run: ./deepstream_test_2 video_file.h264

Hi,

You can use a better alternative!

pyinstaller is not safe. in the directory where pyinstaller produces the executable file, you can find some files in .pyc format. a code thief can easily decompile those files to get your main source code in python. this is because python is an interpreted language (unlike c or c++ which are compiled languages). pyinstaller provides a --key option to remedy this, but again this is not at all safe!

by searching this topic online, one of the safe ways to produce an executable file is via transforming your python code to c code via cython, and then produce an executable file from the generated c file of your code. also, bydoing this, your code would run faster (you will get the performance of a code written in c). I tested this method for deepstream-test2 and it worked perfectly. here are the instructions:

1- install cython:
pip install Cython

2- change the name of your deepstream-test2.py file to deepstream-test2.pyx (this is only a name change, your code remains the same)

3-automatically generate a deepstream-test2.c (in c language) file from your deepstream-test2.pyx (in python language) code by opening up a terminal and running:

cython deepstream-test2.pyx --embed

4- run the following code to generate a deepstream-test2 executable file from the deepstream-test2.c file (which was generated in the previous step):

gcc -Os -I /usr/include/python3.6m -o deepstream-test2 deepstream-test2.c -L/usr/lib/aarch64-linux-gnu -lpython3.6m -lpthread -lm -lutil -ldl

5- run your executable file:

./deepstream-test2 video_file.h264

your executable is now safe! for a thief, decompiling the executable that we just generated, would be a really difficult task.