# Not Importing modules on autostart of python program

**URL:** <https://forums.developer.nvidia.com/t/not-importing-modules-on-autostart-of-python-program/168958>\
**Category:** Jetson Nano\
**Tags:** boot\
**Created:** [February 21, 2021, 10:54am UTC](https://forums.developer.nvidia.com/t/not-importing-modules-on-autostart-of-python-program/168958 "2021-02-21T10:54:50Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prithviraj](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Prithviraj](https://forums.developer.nvidia.com/u/Prithviraj)\
**Post date:** [February 21, 2021, 10:54am UTC](https://forums.developer.nvidia.com/t/not-importing-modules-on-autostart-of-python-program/168958/1 "2021-02-21T10:54:50Z")

</div>

So, let me give a little background on what I’m trying to achieve and where exactly this error is coming.

So, my aim is: As soon as I turn on my Jetson nano my python program would start running. The python program doing object detection and uploading the number of objects in the frame to realtime database on firebase (which in turn we use to display on app). So the important thing is the module firebase.  
So I install firebase using the command:

```auto
pip3 install python-firebase

```

and inside the code we importing these:

```auto
from firebase import firebase
from firebase.firebase import FirebaseApplication

```

So here is where things get interesting, when I run this program through terminal like:

```auto
python3 myscript.py

```

it runs without any problem but as I mentioned above earlier that my aim is to run that program as soon as the jetson gets plugged in, so I’m achieving that like this( i ran a demo script by this method and it works):

> [@How to run a python program as soon as power is turned on Jetson nano jetpack](https://forums.developer.nvidia.com/t/how-to-run-a-python-program-as-soon-as-power-is-turned-on-jetson-nano-jetpack/168757/9):
>
> Create file ~/.config/autostart/myscript.desktop with [Desktop Entry] Encoding=UTF-8 Name=myscript Comment=myscript Icon=gnome-info Exec=python /your/path/script.py Terminal=false Type=Application Categories= X-GNOME-Autostart-enabled=true X-GNOME-Autostart-Delay=0

So this is where the problem comes, when it tries to import all the modules, the process gets exited and when I logged that error it shows (as I can’t see the terminal when this program autostarts):

```auto
No module named firebase

```

It works perfectly fine when executing the script manually but this is the problem I suppose…Can anyone help me out here? I leave the dummy code below to try this.

EDIT: changed title

---

<div class="post-metadata">

**Author:** ![Prithviraj](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Prithviraj](https://forums.developer.nvidia.com/u/Prithviraj)\
**Post date:** [February 21, 2021, 11:00am UTC](https://forums.developer.nvidia.com/t/not-importing-modules-on-autostart-of-python-program/168958/2 "2021-02-21T11:00:57Z")

</div>

Here is the dummy code if want to try it out yourself:

```auto
import cv2
import numpy as np
try:
    from firebase import firebase
    from firebase.firebase import FirebaseApplication
except Exception as error:
    f=open("error.txt","a")
    f.write(str(error))
    f.close()

cap=cv2.VideoCapture(0)

#establishing connnection with the database for the first time

while True:
    try:
        #firebase_message = firebase.FirebaseApplication("<link to the database>", None)    
        break
    except:
        continue
print("Connectionion Established")

while(cap.isOpened()):
    _,frame=cap.read()

   
   # cv2.imshow('frame',result)
    k = cv2.waitKey(1) & 0xff
    if k == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

```

Use this to run your python program on boot

> [@How to run a python program as soon as power is turned on Jetson nano jetpack](https://forums.developer.nvidia.com/t/how-to-run-a-python-program-as-soon-as-power-is-turned-on-jetson-nano-jetpack/168757/9):
>
> Create file ~/.config/autostart/myscript.desktop with [Desktop Entry] Encoding=UTF-8 Name=myscript Comment=myscript Icon=gnome-info Exec=python /your/path/script.py Terminal=false Type=Application Categories= X-GNOME-Autostart-enabled=true X-GNOME-Autostart-Delay=0

please test this dummy code and share if you have a solution to this issue

---

<div class="post-metadata">

**Author:** ![snarky](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/snarky/32/10446_2.png) [@snarky](https://forums.developer.nvidia.com/u/snarky)\
**Post date:** [February 21, 2021, 8:10pm UTC](https://forums.developer.nvidia.com/t/not-importing-modules-on-autostart-of-python-program/168958/3 "2021-02-21T20:10:27Z")

</div>

> [@Prithviraj](#):
>
> ```auto
> from firebase import firebase
> from firebase.firebase import FirebaseApplication
> 
> ```

The first import overwrites the name “firebase” so the second import wouldn’t work. You might succeed if you instead do the second line as `from firebase import FirebaseApplication`

Here’s how samples on the web use this module:

```auto
from firebase import firebase
firebase = firebase.FirebaseApplication('https://your_storage.firebaseio.com', None)

```

---

<div class="post-metadata">

**Author:** ![Prithviraj](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Prithviraj](https://forums.developer.nvidia.com/u/Prithviraj)\
**Post date:** [February 22, 2021, 5:34am UTC](https://forums.developer.nvidia.com/t/not-importing-modules-on-autostart-of-python-program/168958/4 "2021-02-22T05:34:49Z")

</div>

hello @snarky , I tried what u suggested but the problem is coming on the first import.  
And this error occurs when this program runs as soon as I plug in the power in jetson. If I login (through ssh) and then manually execute the script, then there is no issue. It runs smoothly. Any idea why it is not importing?

---

<div class="post-metadata">

**Author:** ![ozguryildiz](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/ozguryildiz/32/72318_2.png) [@ozguryildiz](https://forums.developer.nvidia.com/u/ozguryildiz)\
**Post date:** [February 22, 2021, 6:53am UTC](https://forums.developer.nvidia.com/t/not-importing-modules-on-autostart-of-python-program/168958/5 "2021-02-22T06:53:31Z")

</div>

I think you should try to change the user as root.

> sudo su

You should try to execute your code in root mode. If your application does not run, you should install your python packages in root user.  
You can check the packages with these commands.

> sudo su  
> pip3 list  
> pip3 list | grep

---

<div class="post-metadata">

**Author:** ![Prithviraj](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Prithviraj](https://forums.developer.nvidia.com/u/Prithviraj)\
**Post date:** [February 22, 2021, 7:22am UTC](https://forums.developer.nvidia.com/t/not-importing-modules-on-autostart-of-python-program/168958/6 "2021-02-22T07:22:47Z")

</div>

well, I checked the root user pip3 list, and the firebase module wasn’t there…so I did  
`pip3 install python-firebase` , rebooted the jetson but still same error gets logged…  
`No module named firebase`  
I also check `which pip3` jetson was using in both cases and in both the cases it was:

> /usr/local/bin/pip3

Maybe if you can run the dummy code yourself then you might be able to figure out why it is not importing the module…  
_Note: every time when I manually execute the script, it works, the problem occurs when it autostarts on reboot_

---

<div class="post-metadata">

**Author:** ![ozguryildiz](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/ozguryildiz/32/72318_2.png) [@ozguryildiz](https://forums.developer.nvidia.com/u/ozguryildiz)\
**Post date:** [February 22, 2021, 8:09am UTC](https://forums.developer.nvidia.com/t/not-importing-modules-on-autostart-of-python-program/168958/7 "2021-02-22T08:09:51Z")

</div>

Hello @Prithviraj  
I just tried your dummy code with the autoscript, it works for me on autostart. I used Xavier NX with my custom board and used JetPack 4.5.  
I chose the “autologin” option instead of “require password” option while installing JetPack.

---

<div class="post-metadata">

**Author:** ![Prithviraj](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Prithviraj](https://forums.developer.nvidia.com/u/Prithviraj)\
**Post date:** [February 22, 2021, 11:18am UTC](https://forums.developer.nvidia.com/t/not-importing-modules-on-autostart-of-python-program/168958/8 "2021-02-22T11:18:16Z")

</div>

hey @ozguryildiz , I didn’t get that option while when I installed jetpack (I specially formatted my sd card and installed jetpack again to check that) …But is that the problem? because if I comment the firebase part of the code then on autostart it works fine…it seems like the problem occurs only on the firebase modules…i havent checked for any other…

---

<div class="post-metadata">

**Author:** ![Prithviraj](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Prithviraj](https://forums.developer.nvidia.com/u/Prithviraj)\
**Post date:** [February 23, 2021, 4:34am UTC](https://forums.developer.nvidia.com/t/not-importing-modules-on-autostart-of-python-program/168958/9 "2021-02-23T04:34:17Z")

</div>

okay there is something weird happened…so I imported tensorflow and matplotlib.pyplot to check if the problem is the firebase module or is it other modules as well so… turns out on autostart it logged

> No module named tensorflow  
> No module named matplotlib.pyplot

My guess is, except the default libraries that come with python (in this case: cv2,numpy) it will show the error on autostart for these libraries…  
So if this is the problem then we have to figure out why it is not importing these libraries? Probably it needs to autologin in my user account? @snarky @ozguryildiz

---

<div class="post-metadata">

**Author:** ![Prithviraj](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Prithviraj](https://forums.developer.nvidia.com/u/Prithviraj)\
**Post date:** [February 24, 2021, 2:21pm UTC](https://forums.developer.nvidia.com/t/not-importing-modules-on-autostart-of-python-program/168958/10 "2021-02-24T14:21:24Z")

</div>

okay guys, I figured it out…It was a silly error. All of my dependencies were in `python3` and I was trying to run the code through `python`. Anyways thanks @ozguryildiz @snarky .

Also, I more thing, I want to execute this command first before I execute my script…  
`export LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libgomp.so.1`  
So in turn, I’m executing two commands.  
So what should changes should I make in `~/.config/autostart/myscript.desktop`?

---

<div class="post-metadata">

**Author:** ![ozguryildiz](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/ozguryildiz/32/72318_2.png) [@ozguryildiz](https://forums.developer.nvidia.com/u/ozguryildiz)\
**Post date:** [February 25, 2021, 6:40am UTC](https://forums.developer.nvidia.com/t/not-importing-modules-on-autostart-of-python-program/168958/11 "2021-02-25T06:40:24Z")

</div>

[Desktop Entry]  
Encoding=UTF-8  
Name=myscript  
Comment=myscript  
Icon=gnome-info  
Exec=export LD\_PRELOAD=/usr/lib/aarch64-linux-gnu/libgomp.so.1 && python3 /your/path/script.py  
Terminal=false  
Type=Application  
Categories=

X-GNOME-Autostart-enabled=true  
X-GNOME-Autostart-Delay=0

---

<div class="post-metadata">

**Author:** ![Prithviraj](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Prithviraj](https://forums.developer.nvidia.com/u/Prithviraj)\
**Post date:** [February 25, 2021, 6:48am UTC](https://forums.developer.nvidia.com/t/not-importing-modules-on-autostart-of-python-program/168958/12 "2021-02-25T06:48:15Z")

</div>

hello,  
I achieved the same using

```auto
[Desktop Entry]
Encoding=UTF-8
Name=myscript
Comment=myscript
Icon=gnome-info
Exec="export LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libgomp.so.1 ; python3 /your/path/script.py"
Terminal=false
Type=Application
Categories=

X-GNOME-Autostart-enabled=true
X-GNOME-Autostart-Delay=0

```

Still, thank you for your help and time, I appreciate a lot.

---

<div class="post-metadata">

**Author:** ![nadeemm](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/nadeemm/32/367020_2.png) [@nadeemm](https://forums.developer.nvidia.com/u/nadeemm)\
**Post date:** [October 15, 2021, 5:02am UTC](https://forums.developer.nvidia.com/t/not-importing-modules-on-autostart-of-python-program/168958/13 "2021-10-15T05:02:19Z")

</div>


