0

Please have mercy on me. I'm from the R universe and recently inherited a project in python. It's been about two years since I've had to work with python, so I'm probably missing something obvious. And I'll do my best for a reprex if anyone should deem it necessary.

I have an anaconda environment running on ubuntu 20.04. I've activated the environment and then installed biopython. However, whenever I run the script file in question, I get a ModuleNotFoundError. Here's the full error:

from Bio import SeqIO ModuleNotFoundError: No module named 'Bio'

After doing some digging, turns out Bio is actually within biopython, and when I run conda list | grep 'Bio' I get nothing as output. However, when I run conda list | grep 'bio' here's the output.

# packages in environment at /home/user/anaconda3/envs/bioPy: biopython 1.78 py38h7b6447c_0

Here's the output from which python3

/home/user/anaconda3/envs/bioPy/bin/python3

I also fired up the interpreter directly, from within the active environment then ran import Bio then used the methods I wanted to use, and had no issues. But if I tried to import biopython I get a ModuleNotFoundError. So I'm pretty sure that Bio is what I actually need for the script to run

I read in this post about manually changing the name of the package directory in the site-packages directory located at /home/user/anaconda3/lib/python3.x/site-packages. Seemed far-fetch, but didn't make a difference because the directory was already named 'Bio' in site-packages.

I see from the biopython website that Bio is the API for the biopython project, and that the particular piece of code I want is a separate package within the API (SeqIO).

So here's my question. How is one supposed to get methods from within the Bio package imported into a python script?

aromatic6tet
  • 91
  • 1
  • 8
  • Probably an issue with pathing due to how you are calling the anaconda environment. Some useful resources: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html https://www.biostars.org/p/396486/ – Ghoti Jan 19 '21 at 21:48
  • Import 'sys' module and run: `print(sys.version)` and `print(sys.path)` – Ghoti Jan 19 '21 at 21:49
  • Please provide the printed output when you run this via interpreter and bash (conda env). – Ghoti Jan 19 '21 at 21:51
  • `print(sys.version)` yields: `3.8.5 (default, Sep 4 2020, 07:30:14) [GCC 7.3.0]` and `print(sys.path)` yields: `['', '/home/user/anaconda3/envs/bioPy/lib/python38.zip', '/home/user/anaconda3/envs/bioPy/lib/python3.8', '/home/user/anaconda3/envs/bioPy/lib/python3.8/lib-dynload', '/home/user/anaconda3/envs/bioPy/lib/python3.8/site-packages']` – aromatic6tet Jan 19 '21 at 22:05
  • You are able to use 'Bio' via interpreter but not via bash (assuming this is how you encountered `ModuleNotFoundError`. Please provide the output for both interpreter (method you can load 'Bio') AND bash (method you cannot load 'Bio'). I'm guessing you'll get different results, which shouldn't be the case. – Ghoti Jan 19 '21 at 22:34
  • If you do get different results, you'll want to look at how you're calling the conda python environment (review documentation). – Ghoti Jan 19 '21 at 22:38
  • Thank you @Ghoti for the response. I won’t be able to access that machine again until tomorrow at the earliest. One question though, when you say “calling” the conda environment do you mean calling `conda activate` or `conda create`? – aromatic6tet Jan 19 '21 at 23:32
  • I mean whatever method you've been trying to use unsuccessfully (bash). Sorry for the confusion. – Ghoti Jan 20 '21 at 17:31
  • Interpreter output: ` ` Bash output: `Traceback (most recent call last): File "/home/user/Desktop/Scripts/run_fastq_analyzer.py", line 11, in from Bio import SeqIO ModuleNotFoundError: No module named 'Bio'` – aromatic6tet Jan 20 '21 at 18:08

0 Answers0