Page 1 of 1

I/O error, CGI, Installing library

Posted: Sat Oct 13, 2012 7:45 pm
by pjblink
Hi all,

I'm getting fairly competent now at writing python code etc, but i'm still quite new to it. I have the BMP085 barometric pressure sensor, and am using the Adafruit module libary for it. My code has worked so far, and i've got what I want out of it, but one thing has been bugging me. The library is just a folder with .py and .pyc files. I've never quite worked out how to properly "install" this library. I've always just had the files in the same folder as the scripts i'm working on. How do i go about properly installing the library?

This has only really been a problem now as i'm attempting to write CGI scripts for reading sensor readings online, where I will be writing a dynamic html page to present the data. I have CGI scripts now working using apache within a "/var/www/cgi-bin" folder, where i'm fine importing time and inserting this into html etc. The issue i'm now getting is using the Adafruit_BMP085 library. As before, the only way i can get it anywhere near working (still not getting data) is to place the .py files into the same cgi-bin folder, which i'm guessing isn't the most efficient.

The error log from apache is shown below, where you can see it running through the BMP and I2C libraries until it hits an "IOError: [Errno 13] Permission denied".

Can anyone help me work out what's my issue? And how to properly install these libraries?

Code: Select all

[Sat Oct 13 20:17:14 2012] [error] [client 192.168.1.67] Traceback (most recent call last):, referer: http://192.168.1.90/cgi-bin/
[Sat Oct 13 20:17:14 2012] [error] [client 192.168.1.67]   File "/var/www/cgi-bin/airpressuretest.cgi", line 4, in <module>, referer: http://192.168.1.90/cgi-bin/
[Sat Oct 13 20:17:14 2012] [error] [client 192.168.1.67]     , referer: http://192.168.1.90/cgi-bin/
[Sat Oct 13 20:17:14 2012] [error] [client 192.168.1.67] from Adafruit_BMP085 import BMP085, referer: http://192.168.1.90/cgi-bin/
[Sat Oct 13 20:17:14 2012] [error] [client 192.168.1.67]   File "/var/www/cgi-bin/Adafruit_BMP085.py", line 4, in <module>, referer: http://192.168.1.90/cgi-bin/
[Sat Oct 13 20:17:14 2012] [error] [client 192.168.1.67]     , referer: http://192.168.1.90/cgi-bin/
[Sat Oct 13 20:17:14 2012] [error] [client 192.168.1.67] from Adafruit_I2C import Adafruit_I2C, referer: http://192.168.1.90/cgi-bin/
[Sat Oct 13 20:17:14 2012] [error] [client 192.168.1.67]   File "/var/www/cgi-bin/Adafruit_I2C.py", line 9, in <module>, referer: http://192.168.1.90/cgi-bin/
[Sat Oct 13 20:17:14 2012] [error] [client 192.168.1.67]     , referer: http://192.168.1.90/cgi-bin/
[Sat Oct 13 20:17:14 2012] [error] [client 192.168.1.67] class Adafruit_I2C :, referer: http://192.168.1.90/cgi-bin/
[Sat Oct 13 20:17:14 2012] [error] [client 192.168.1.67]   File "/var/www/cgi-bin/Adafruit_I2C.py", line 11, in Adafruit_I2C, referer: http://192.168.1.90/cgi-bin/
[Sat Oct 13 20:17:14 2012] [error] [client 192.168.1.67]     , referer: http://192.168.1.90/cgi-bin/
[Sat Oct 13 20:17:14 2012] [error] [client 192.168.1.67] def __init__(self, address, bus=smbus.SMBus(1), debug=False):, referer: http://192.168.1.90/cgi-bin/
[Sat Oct 13 20:17:14 2012] [error] [client 192.168.1.67] IOError: [Errno 13] Permission denied, referer: http://192.168.1.90/cgi-bin/
[Sat Oct 13 20:17:14 2012] [error] [client 192.168.1.67] Premature end of script headers: airpressuretest.cgi, referer: http://192.168.1.90/cgi-bin/

Re: I/O error, CGI, Installing library

Posted: Sat Oct 13, 2012 8:03 pm
by pjblink
I've since copied the py and pyc files into "/usr/lib/python2.7/"

Is that correct and sufficient? I can see from the error log that it is now finding the library files in their new folder. I'm still obviously getting the I/O error though.

Re: I/O error, CGI, Installing library

Posted: Sun Oct 14, 2012 10:03 pm
by pjblink
I've since found the answer to this. I needed to correct the permissions on /dev/i2c. Updating these (i2c-0 and i2c-1), and the script is now working!