the-raspberry-pi-guy / lcd

This repository contains all of the code for interfacing with a 16x2 Character I2C LCD Display. This accompanies my YouTube tutorial here: https://www.youtube.com/watch?v=fR5XhHYzUK0
186 stars 107 forks source link

module not imported running python script at startup raspberry pi /etc/profiles #55

Closed Murali-IsPagro closed 2 years ago

Murali-IsPagro commented 2 years ago

I created a python script using lcd. It works perfectly fine when I am testing from CLI. I have an application where I have to run the script during start up. So I have done these steps:

  1. sudo nano /etc/profile

  2. added "sudo python3 /home/pi/test_adc_1.py &" in the last line.

  3. sudo reboot now

But code didnt start, so i logged on to RPi and checked it displays below error.

**pi@raspberrypi:~ $ Traceback (most recent call last): File "/home/pi/test_adc_1.py", line 3, in import drivers ModuleNotFoundError: No module named 'drivers'

[1]+ Exit 1 sudo python3 /home/pi/test_adc_1.py**

Kindly suggest me the solution.

cgomesu commented 2 years ago

sudo nano /etc/profile

try https://github.com/the-raspberry-pi-guy/lcd#systemd instead. a systemd service unit file is a better way of running such things.

Traceback (most recent call last):
File "/home/pi/test_adc_1.py", line 3, in import drivers
ModuleNotFoundError: No module named 'drivers'

see https://duckduckgo.com/?t=ffab&q=python+import+relative+absolute+paths.

Murali-IsPagro commented 2 years ago

This one fixed the error. Now working fine.

Thanks!