Why can't import Biopython module when I run my scripts located in /usr/lib/cgi-bin?
1
0
Entering edit mode
5.5 years ago
lhernanj • 0

Hello,

I am user of ubuntu and I run many scripts written with python3 which was installed through anaconda. All modules that I need have been installed there previously i.e. biopython. However, I can't import biopython in one of my script when I try to run my script from /usr/lib/cgi-bin

from Bio import SeqIO #it doesn't work

The ERROR is:

A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.
ImportError: No module named 'Bio'
      args = ("No module named 'Bio'",)
      msg = "No module named 'Bio'"
      name = 'Bio'
      path = None
      with_traceback = <built-in method with_traceback of ImportError object>

I have tried the advices proposed on Why can't python find some modules when I'm running CGI scripts from the web? or https://www.raspberrypi.org/forums/viewtopic.php?t=50225

In the first case, sudo permissions to www-data create a warning of security because I am using the server from a public institution. The second case is for raspberrypi

Can someone help me with that problem?

biopython • 5.4k views
ADD COMMENT
1
Entering edit mode

Did you made the python file executable and if yes are you not using a wrong shebang line?

Some extra info to do some easy checks:

Execute from the command line:

which python3

If it says that you are using the one from conda your are good, if not you now know your problem.(tip: check your $PATH)

Next start python3 from the commandline by simply executing:

python3

If you are inside the python3 program you can type and press enter:

import Bio

If you get an import error biopython is not installed. If you don't get an error biopython works and your script should work if you execute:

python3 yourscript.py

And the last thing but is unlikely, make sure there is no python3 symlink in your /usr/lib/cgi-bin folder.

ADD REPLY
0
Entering edit mode

Are you sure the cgi-bin python binary is 'pointing at' the conda python binary? I suspect youre packages are set up for the 'wrong' Python.

ADD REPLY
0
Entering edit mode

I am not sure, could you help me. Do you know how can I check that?

ADD REPLY
0
Entering edit mode

A quick way to check would be make a script inside the cgi-bin, which prints the system executable:

import sys
sys.executable

If that prints a path with anaconda, then it will be another issue.

Webservers are not an area of expertise for me though, so someone else will probably also need to weigh in.

ADD REPLY
0
Entering edit mode

I guess that my problem is: I don't know how to share anaconda packages with the user of HTTP server because the HTTP server executes my scripts as user “nobody”.

ADD REPLY
0
Entering edit mode

I suspect that is more likely the case.

This question is probably better directed at StackOverflow. I won’t go so far as to close it just yet, in case there is some behaviour specific to BioPython, but I doubt thats likely to be so.

This is more a question about web server config/package management than bioinformatics at this point.

ADD REPLY
0
Entering edit mode

Ok, I agree. I sent the same question to StackOverflow but nobody answered me with a real solution.

ADD REPLY
0
Entering edit mode
5.5 years ago
lhernanj • 0

SOLUTION: Removing anaconda from home directory and install it in usr/local. Thus, Apache will have permission to access the environment.

a) Remove anaconda with $ rm -rf anaconda3/ b) Re-install anaconda3 in directory /usr/local c) Add the line export PATH='/usr/local/anaconda3/bin:$PATH' to the end of your /root/.bashrc file d) Verify that the root user is using the right version of Python: $ which python

That's all

ADD COMMENT
2
Entering edit mode

Good that you solved it, but I want to add that you could install anaconda in the /opt folder. This folder is made for this kind of things.

http://www.tldp.org/LDP/Linux-Filesystem-Hierarchy/html/opt.html

https://sourcedigit.com/22484-linux-opt-directory-open-opt-directory/

http://www.extradrm.com/?p=2266

ADD REPLY

Login before adding your answer.

Traffic: 2799 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6