views:

30

answers:

2

I have no idea what could be the problem here:

I have some modules from Biopython which I can import easily when using the interactive prompt or executing python scripts via the command-line.

The problem is, when I try and import the same biopython modules in a web-executable cgi script, I get a "Import Error"

: No module named Bio

Any ideas here?

+1  A: 

In the cgi script, you could try to add the path to this package before any import.

sys.path.insert(0, 'path to biopython package')

If you are using Apache, you should be able to set the PYTHONPATH in conf file with directive SetEnv

SetEnv PYTHONPATH "path to biopython package"
pyfunc
I've tried adding the path by way of "sys.path.insert", the thing is, the containing folder already shows up when I enter "sys.path" into the interactive prompt. I am using apache.
Mr. Dave
+1  A: 

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.
Doug
By running sys.version on the interactive prompt, it looks like Apache was running a different version of python than the once accessible from bash. Since I don't have root access, I'm going to try and install biopython locally in my home. Thanks!
Mr. Dave