0

BMP Python lib and rc.local
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

BMP Python lib and rc.local

by pmeloy on Fri Feb 08, 2019 2:06 pm

I'm trying to run a script that uses the BMP085 library from rc.local but it tells me that BMP085 library doesn't exist. I've tried various ways of declaring the device to no avail. Then I clued in and realized rc.local runs as root, not pi, so the paths may be different. I tried starting the script with pi as the user and now it finds the library but it insists BMP085 is not defined. Of course it runs fine from console or WingIDE.

Any tips?

Code: Select all | TOGGLE FULL SIZE
import Adafruit_BMP.BMP085 as BMP085
...
bmp = BMP085.BMP085()


rc.local entry: (sleep 10;sudo -H -u pi python /home/pi/public/python/WeatherStation/WeatherStation/WeatherStation.py) &

Log:
Feb 08 09:42:45 RaspiWeather rc.local[505]: File "/home/pi/public/python/WeatherStation/WeatherStation/WeatherStation.
Feb 08 09:42:45 RaspiWeather rc.local[505]: bmp = BMP085.BMP085()
Feb 08 09:42:45 RaspiWeather rc.local[505]: NameError: name 'BMP085' is not defined

Edit: I should mention the BMP library was installed using pip, not manually.

pmeloy
 
Posts: 24
Joined: Tue Sep 19, 2017 2:26 pm

Re: BMP Python lib and rc.local

by adafruit_support_mike on Mon Feb 11, 2019 5:58 am

Check to make sure you've installed the library with the same interpreter that will run the code.

Pyhton-2.7 and Python-3 are only kind-of-compatible, and a lot of Python-2.7 modules are deprecated or won't work in Python-3. Because of that, the two versions have separate file trees for loadable modules.

If you installed the code using a Python-2.7 interpreter, it won't be visible to Python-3, and vice versa.

adafruit_support_mike
 
Posts: 57095
Joined: Thu Feb 11, 2010 2:51 pm

Re: BMP Python lib and rc.local

by pmeloy on Sun Feb 17, 2019 2:52 pm

I'm using Python 2.7 and it doesn't complain about the DHT library...

pmeloy
 
Posts: 24
Joined: Tue Sep 19, 2017 2:26 pm

Re: BMP Python lib and rc.local

by adafruit_support_mike on Mon Feb 18, 2019 2:00 am

The interpreter is complaining about the BMP085 library. Make sure you installed that in the Python-2.7 file tree.

adafruit_support_mike
 
Posts: 57095
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.