0

I have a conda virtual environment with Python 3.7.16 and several installed libraries such as 'lifelines', etc. In the conda console all the installed libraries are shown; however, when I open a Jupyter Notebook on the same environment and try to load, for example, the library 'lifelines', it gives me the error message ModuleNotFoundError: No module named 'lifelines'.

I have searched on Github and Stack Overflow, and tried several solutions such as this one and others, but I still can't import libraries on Jupyter Notebooks that are already installed in the conda environment.

Does anybody know how to solve this issue?

  • 1
    Are you adding the conda environment to the notebook fully or choosing the kernel from the environment inside Jupyter? See the second section [here](https://stackoverflow.com/a/67198468/8508004) or other related things [here](https://towardsdatascience.com/get-your-conda-environment-to-show-in-jupyter-notebooks-the-easy-way-17010b76e874) or [here](https://github.com/jupyter/notebook/issues/3311#issuecomment-406740348). (Note the one you linked to is duplicating things, which is sometimes a good strategy to just get past things on a system you don't care about keeping clean. You'd ... – Wayne Feb 15 '23 at 16:17
  • preferably stick with the conda based commands because that is your primary package manager based on the first sentence in your post. And to make it easier there is now magic install commands for running inside a Jupyter `.ipynb` file that insure you install in the environment backing the kernel. So assuming that [there](https://stackoverflow.com/a/67636947/8508004) has the command correct, in a cell in your notebook, you can run `%conda install -c conda-forge lifeline`, restart the kernel, and the import now should work. Note there's a chance then that you've installed ... – Wayne Feb 15 '23 at 16:25
  • that package twice on your machine, but sometimes that is an easier compromise to go with to get things at least working. If you care to learn more about the modern magic install commands for use from inside a cell in an `.ipynb` file, see [here](https://discourse.jupyter.org/t/why-users-can-install-modules-from-pip-but-not-from-conda/10722/4?u=fomightez).) – Wayne Feb 15 '23 at 16:27
  • 1
    Thanks @Wayne in fact, I didn't install jupyter in that particular environment, so it was searching in the base one. I installed the jupyter and now everything works good! – Ernesto Lopez Fune Feb 16 '23 at 09:15

1 Answers1

0

In fact, I needed to install Jupyter-lab and notebook in the same environment; otherwise it was searching for all libraries in the base one.