micom-dev / micom

Python package to study microbial communities using metabolic modeling.
https://micom-dev.github.io/micom
Apache License 2.0
82 stars 17 forks source link

Issue importing #4

Closed arianccbasile closed 5 years ago

arianccbasile commented 5 years ago

while import micom version 0.9.2 I got the following ImportError. Any suggestion to solve it?

Sincerely, Arianna Basile


ImportError Traceback (most recent call last) /mnt/data_SSD/anaconda3/envs/flux_balance/lib/python3.6/site-packages/swiglpk/swiglpk.py in swig_import_helper() 13 try: ---> 14 return importlib.import_module(mname) 15 except ImportError:

/mnt/data_SSD/anaconda3/envs/flux_balance/lib/python3.6/importlib/init.py in import_module(name, package) 125 level += 1 --> 126 return _bootstrap._gcd_import(name[level:], package, level) 127

/mnt/data_SSD/anaconda3/envs/flux_balance/lib/python3.6/importlib/_bootstrap.py in _gcd_import(name, package, level)

/mnt/data_SSD/anaconda3/envs/flux_balance/lib/python3.6/importlib/_bootstrap.py in _find_andload(name, import)

/mnt/data_SSD/anaconda3/envs/flux_balance/lib/python3.6/importlib/_bootstrap.py in _find_and_loadunlocked(name, import)

/mnt/data_SSD/anaconda3/envs/flux_balance/lib/python3.6/importlib/_bootstrap.py in _load_unlocked(spec)

/mnt/data_SSD/anaconda3/envs/flux_balance/lib/python3.6/importlib/_bootstrap.py in module_from_spec(spec)

/mnt/data_SSD/anaconda3/envs/flux_balance/lib/python3.6/importlib/_bootstrap_external.py in create_module(self, spec)

/mnt/data_SSD/anaconda3/envs/flux_balance/lib/python3.6/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

ImportError: libglpk.so.40: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

ModuleNotFoundError Traceback (most recent call last)

in ----> 1 import micom 2 import cplex 3 import cobra 4 import pandas 5 import gurobi /mnt/data_SSD/anaconda3/envs/flux_balance/lib/python3.6/site-packages/micom/__init__.py in 1 """Simple init file for mico.""" 2 ----> 3 from micom.community import Community, load_pickle 4 from micom import (algorithms, problems, util, data, duality, media, 5 solution, workflows) /mnt/data_SSD/anaconda3/envs/flux_balance/lib/python3.6/site-packages/micom/community.py in 12 from micom.logger import logger 13 from micom.media import default_excludes ---> 14 from micom.optcom import optcom, solve 15 from micom.problems import cooperative_tradeoff, knockout_species 16 /mnt/data_SSD/anaconda3/envs/flux_balance/lib/python3.6/site-packages/micom/optcom.py in 5 check_modification) 6 from micom.logger import logger ----> 7 from micom.solution import solve 8 from optlang.symbolics import Zero 9 from functools import partial /mnt/data_SSD/anaconda3/envs/flux_balance/lib/python3.6/site-packages/micom/solution.py in 14 from micom.logger import logger 15 from micom.util import reset_min_community_growth ---> 16 from swiglpk import glp_adv_basis 17 18 /mnt/data_SSD/anaconda3/envs/flux_balance/lib/python3.6/site-packages/swiglpk/__init__.py in ----> 1 from .swiglpk import * /mnt/data_SSD/anaconda3/envs/flux_balance/lib/python3.6/site-packages/swiglpk/swiglpk.py in 15 except ImportError: 16 return importlib.import_module('_swiglpk') ---> 17 _swiglpk = swig_import_helper() 18 del swig_import_helper 19 elif _swig_python_version_info >= (2, 6, 0): /mnt/data_SSD/anaconda3/envs/flux_balance/lib/python3.6/site-packages/swiglpk/swiglpk.py in swig_import_helper() 14 return importlib.import_module(mname) 15 except ImportError: ---> 16 return importlib.import_module('_swiglpk') 17 _swiglpk = swig_import_helper() 18 del swig_import_helper /mnt/data_SSD/anaconda3/envs/flux_balance/lib/python3.6/importlib/__init__.py in import_module(name, package) 124 break 125 level += 1 --> 126 return _bootstrap._gcd_import(name[level:], package, level) 127 128 ModuleNotFoundError: No module named '_swiglpk'
cdiener commented 5 years ago

Hi, this looks similar to issues we observed in cobrapy when installing the conda version of cobrapy. Could you walk me through how you installed cobrapy?

With conda, the following seems to work:

conda create -n micom-py3 "python>=3.6" pandas tqdm
source activate micom-py3
pip install micom

Which seems to give a working micom:

(micom-py3)  ~ python
Python 3.7.1 | packaged by conda-forge | (default, Mar 13 2019, 05:40:40)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import micom
>>> tax = micom.data.test_taxonomy()
>>> com = micom.Community(tax)
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:00<00:00,  5.03models/s]
>>> com.optimize()
<CommunitySolution 0.874 at 0x119abf048>
>>>

Hope that helps

arianccbasile commented 5 years ago

I solved with this. pip install -U swiglpk optlang pip install optlang==1.4.2

Actually I am on python2.7, do you recommend the other?

Sincerely, Arianna Basile

cdiener commented 5 years ago

Thanks for the update. micom works with Python 2 and 3 for now. This will only affect other dependencies such as pandas that have already dropped Python 2 support.