3

I have a fresh installation of Anaconda on OS X, and I'm following the instructions on this page to the letter, in order to create the appropriate environment.

When I enter conda list after activating the environment, pandas and matplotlib are both listed.

But when I open the provided jupyter notebook, or when I create a new jupyter notebook and type import pandas as pd, I get a 'there is no module called pandas' error. Ditto for matplotlib.

Happy to provide any more information that would be helpful in figuring out the problem. I feel like I run into problems like this a lot, so general strategies for debugging this kind of thing are welcome. Thanks!

EDIT: OK, I've fixed the problem for now, but I still feel like I'm missing something.

The problem was that there was no jupyter/ipython notebook kernel for the version of python in this env. So when I launch the notebook, even within the env, the correct version of python doesn't load, and some packages aren't available.

The solution is to add the kernel as described here: Using both Python 2.x and Python 3.x in IPython Notebook

It seems a bit odd to have to install a different ipython-kernel for every environment, but maybe it's not. I guess I just thought the correct version of python would load in the notebook as long as the notebook was launched from the env.

Does anyone have a better solution?

Community
  • 1
  • 1
jwdink
  • 4,824
  • 5
  • 18
  • 20
  • can you give us all steps from the installation of anaconda to the installation of the package? – cel Dec 08 '15 at 05:36
  • 1
    I had the same issue, the weird thing is it has been working before. I don't know if I changed something in the meantime. I had to execute `conda install notebook ipykernel` and `ipython kernel install --user` and then it was working again. Thanks for sharing and pointing to the other question! – Verena Haunschmid Oct 10 '16 at 16:25
  • 5 yrs late but i have the same very problem and found the same - odd- solution. Wondering if @jwdink or someone else has been able to found a better\cleaner solution than duplicate the kernel in each env? Or if it's already the best practive available already, so i may be aware of that! thanks! – Carlo Oct 15 '21 at 11:06

1 Answers1

0

Since both your Py2 and Py3 kernels need different, version specific sets of packages to support them, the best and most convenient solution seems to be the one it sounds like you followed -- use anaconda, install either version as your default, then install an env with the other. If you want pandas available to both versions, you will need to make sure you conda install it in both the root and the other env. Jupyter is a bit magical in that it can be launched from either environment, yet will recognize that an ipython kernel exists in a different env and make both available to you.

It sounds like this may have worked against you slightly, though, and that you either launched jupyter from an env that didn't have ipython installed, but did have pandas. Jupyter found the ipython kernel in the other env, but you didn't have pandas installed there yet. At lest thats a theory. Solution remains to install pandas and ipython in both. Doing conda install anaconda in both envs will give you lots of packages, if space isn't a concern and may save you some of this aggrivation.

Alnilam
  • 3,121
  • 2
  • 21
  • 22