jupyter notebook can't import cobra

317 views
Skip to first unread message

Jason Young

unread,
Nov 15, 2021, 12:32:19 PM11/15/21
to cobra pie

Firstly, I installed cobra globally, but because I want to use carvme based on cplex, I created a new environment for consolidating python3.6. When I try to import cobra using jupyter notebook in a new environment, it shows an error "ModuleNotFoundError: No module named 'cobra'" . But it can be successfully imported in my linux python.

This means that in the new environment, cobra can be imported in the terminal but not in jupyter. I spent some time trying to find the possible reasons. When I used "import sys; sys.path", the terminal and jupyter notebook gave different results. I find the different is there is home/zhiyan/anaconda3/envs/python36env/lib/python3.6/site-packages in linux python but no in jupyter notebook.

I am not sure if this is the reason, because I don't know how to go to jupyter Add PATH.

image (1).png

Thanks a lot.

ch.d...@gmail.com

unread,
Nov 15, 2021, 5:18:38 PM11/15/21
to cobra pie
Did you install the jupyter notebook in the particular environment as well? You need at least the kernel installed otherwise it will not give you an option to run the notebook using the python from the environment. The easiest fix is probably to activate the env in your terminal (`conda activate my_env`), then install jupyter using conda `conda install -c conda-forge -c defaults jupyterlab`.

Jason Young

unread,
Nov 16, 2021, 9:51:14 AM11/16/21
to cobra pie
Thanks a lot, I create a new env and install everything. It works now, thanks a lot :)
Reply all
Reply to author
Forward
0 new messages