API: import qiime2, No module named 'qiime2'

I am having some difficulties getting the API functioning. I can see the qiime2 environment, but no importable module or plugins.

#!/usr/bin/env python3.8
import Bio
import pandas as pd
import qiime2 as q2

Bio and pandas import, but qiime2 does not.

ModuleNotFoundError: No module named ‘qiime2’

The most recent environment is qiime2-2021.2 installed through miniconda.

conda list for reference.

_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       1_gnu    conda-forge
bio                       0.4.1                    pypi_0    pypi
biopython                 1.78             py38h497a2fe_2    conda-forge
blas                      1.0                         mkl  
brotlipy                  0.7.0           py38h27cfd23_1003  
ca-certificates           2021.4.13            h06a4308_1  
certifi                   2020.12.5        py38h06a4308_0  
cffi                      1.14.5           py38h261ae71_0  
chardet                   4.0.0           py38h06a4308_1003  
conda                     4.10.0           py38h06a4308_0  
conda-package-handling    1.7.3            py38h27cfd23_1  
cryptography              3.4.7            py38hd23ed53_0  
idna                      2.10               pyhd3eb1b0_0  
intel-openmp              2020.2                      254  
ld_impl_linux-64          2.33.1               h53a641e_7  
libffi                    3.3                  he6710b0_2  
libgcc-ng                 9.3.0               h2828fa1_18    conda-forge
libgomp                   9.3.0               h2828fa1_18    conda-forge
libstdcxx-ng              9.1.0                hdf63c60_0  
mkl                       2020.2                      256  
mkl-service               2.3.0            py38he904b0f_0  
mkl_fft                   1.3.0            py38h54f3939_0  
mkl_random                1.1.1            py38h0573a6f_0  
ncurses                   6.2                  he6710b0_1  
numpy                     1.19.5                   pypi_0    pypi
numpy-base                1.19.2           py38hfa32c7d_0  
openssl                   1.1.1k               h27cfd23_0  
pandas                    1.2.3                    pypi_0    pypi
pip                       21.0.1           py38h06a4308_0  
pycosat                   0.6.3            py38h7b6447c_1  
pycparser                 2.20                       py_2  
pyopenssl                 20.0.1             pyhd3eb1b0_1  
pysocks                   1.7.1            py38h06a4308_0  
python                    3.8.5                h7579374_1  
python-dateutil           2.8.1                    pypi_0    pypi
python_abi                3.8                      1_cp38    conda-forge
pytz                      2021.1                   pypi_0    pypi
readline                  8.1                  h27cfd23_0  
requests                  2.25.1             pyhd3eb1b0_0  
ruamel_yaml               0.15.100         py38h27cfd23_0  
setuptools                52.0.0           py38h06a4308_0  
six                       1.15.0           py38h06a4308_0  
sqlite                    3.35.4               hdfb4753_0  
tk                        8.6.10               hbc83047_0  
tqdm                      4.59.0             pyhd3eb1b0_1  
urllib3                   1.26.4             pyhd3eb1b0_0  
wheel                     0.36.2             pyhd3eb1b0_0  
xmltodict                 0.12.0                   pypi_0    pypi
xz                        5.2.5                h7b6447c_0  
yaml                      0.2.5                h7b6447c_0  
zlib                      1.2.11               h7b6447c_3

Hi @A_Bennett,

My first (naive) question is whether you have activated the qiime2 conda enviroment environment as you’re executing the script. I find it often helps me to work inside a Jupyter notebook for similar development and testing. (You can always export the notebook to a python script).

Best,
Justine

is whether you have activated the qiime2 conda enviroment environment as you’re executing the script.

I am attempting to run the script without activating the environment. Activation of the environment before executing the script causes all of the modules to not be found: Bio, pandas, qiime2.

Hi @A_Bennett,

QIIME 2 is not importable outside your qiime2 conda enviroment. The system cannot see it in the path. (This is a feature of conda!). So, if you wish to execute your script, it must be done inside that conda environment. You may need to install the Bio package (pip and conda both work pretty well in my experience.) Pandas ships with qiime2, so there’s no need to install that.

You may also be having an issue with the python3.8. I would check the version shipped with qiime2-2021.2; it think that environment is still python 3.6.

Best,
Justine

3 Likes

@jwdebelius

Thank you. The issues were 1) Not in qiime2 environment 2) Using python 3.8.

3 Likes

The upcoming 2021.4 release upgrades QIIME 2 to Python 3.8, btw!

1 Like