HCRuiz
HCRuiz

Reputation: 85

jupyter doesn't import numpy after upgrade with anaconda

I updated the packages with conda update --all and was using jupyter to work. Before the update, everything was working, but now jupyter doesn't import any module beside the sys, os, copy and time. Numpy, matplotlib and theano are not being imported. But they are definitely in the conda list... the python version is 2.7.12

When I updated with conda, I remember that there was a message that numpy was being deprecieted due to conflicts. Now in the conda list I have numpy 1.11.1.

I'm new in python, so I don't understand the import error. Before uninstalling everything again, I would like to understand what the problem is to learn and of course to continue using jupyter ;) I found this post https:// github.com/jupyter/notebook/issues/397 (sorry I can't link it, I'm new here) which seems to be a problem related to mine or similar, but I don't think I understand it so well... so before I break more I wanted to ask here!

Is jupyter badly "connected" to anaconda? How can I check where the packages are being searched? For any comment on this I would be very grateful!! Here are the cells of jupyter:

cells of jupyter

and the Error I get:

ImportError

Thanks!

Upvotes: 2

Views: 2225

Answers (2)

Jazz
Jazz

Reputation: 475

That import error is due to change in environment of the jupyter notebook. You might have installed the packages in one environment and you are running the jupyter notebook in another environment.

  1. I have got two environments (envs) in my Anaconda folder. I have Anaconda3 folder to be specific).

  2. (windows key+cmd) -> open the windows command prompt run as administrator.

  3. Activate (name of the environment) -> eg.: activate tensorflow-gpu

  4. Start installing packages using conda install

Note: For each environment you need to install all the packages you want to use, separately using the same process. This solution is for windows users, might work for linux users not sure though.

Additionally to make sure your conda environment is up to date run:

conda update conda
conda update anaconda

For more information: https://pradyumnamajumder.wordpress.com/2017/09/30/solution-to-the-python-packages-import-error-in-jupyter/

Upvotes: 2

HCRuiz
HCRuiz

Reputation: 85

I followed the idea as in here and changed the file that launches the root jupyter command (cf. cat /dir_where_installed/anaconda2/bin/jupyter and the jupyter-notebook ( cf. cat /dir_where_installed/anaconda2/bin/jupyter-notebook).

It was set as in the anaconda environment conda info --envs as expected (both files had in the first line something like #! /dir_where_installed/anaconda2/bin/python), but for some reason after the update I did and even after installing again everything(!), jupyter wasn't taking that path, instead it was importing from the 'stock' python (apparently).
Anyway, I changed both lines with #! to take the path as in the output of which python.

Summary:

  1. check path in cat /dir_where_installed/anaconda2/bin/jupyter and cat /dir_where_installed/anaconda2/bin/jupyter-notebook
  2. which python out put should be something like /usr/bin/python
  3. substitute the lines in both files starting with #! with #! /usr/bin/python
    I'm not sure if this is a good idea, but it worked for me and now I can import all packages in jupyter. If anyone has any idea if this is a bad idea or a better solution, please let me know!

Upvotes: 1

Related Questions