I’ve never attempted to use Python CGI before- I’d probably accomplish the same thing with a Flask server to avoid that extra complexity.
However, this looks like it might be relevant (albeit you’ve already tried to address point 2):
Here are a couple of possibilities:
Apache (on Unix) generally runs as a different user, and with a different environment, to python from the command line. Try making a small script that just prints out sys.version and sys.prefix, and compare the result through apache and via the command line, to make sure that you’re running from the same installation of python in both environments.
Is Biopython installed under your home directory, or only readable just for your normal user? Again, because apache generally runs as a different user, perhaps you don’t have access to that location, so can’t import it.
Can you try doing import site before trying to import Biopython? Perhaps something is preventing site packages from being imported when you run through apache.
for security reasons, the HTTP server executes your script as user “nobody”, without any special privileges. It can only read (write, execute) files that everybody can read (write, execute)
this is your problem right there… unless that ‘nobody’ user has access to the i2c (and gpio) group then it will fail, because the SMBus instance of class cannot be created.
how you go about sorting that out I’m not entirely sure. I guess that the cgi module creates a user on installation? if so then it should be possible to add it to those groups. If not then, opening permissions of the i2c and gpio groups to all users would be needed.
reading up on the purpose of user nobody I’d say that it would probably be frowned upon amending its own privileges, so that leaves opening up the i2c and gpio to everybody (not that does not carry its own security risk, you’ll have to consider whether that would be a concern for you).
Thanks for all of the suggestions.
I thought I would give Flask a try since it seems a much simpler solution, however I ran into issues there as well. I installed flask and ran through the first few examples in the tutorial, however when I added the “import explorerhat” statement to even the hello-flask sample it gave me an error “Warning, could not find analog or touch … Please check your i2c settings”. I think at this point I will resign myself to the fact that the explorer hat module has some features that don’t play well with other software, which is unfortunate because it’s a pretty cool tool.