2

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!

HCRuiz
  • 65
  • 10
  • If you can import sys, please import sys, and see the output of sys.path, which will show a list of path. if you already installed anaconda, the path should have something like .../anaconda2/lib/python2.7/..... . Can you show me that – Tian Zhang Jul 21 '16 at 14:32
  • Thanks! out put of `sys.path` is:// '/scratch/hruiz/anaconda2/lib/python27.zip', '/scratch/hruiz/anaconda2/lib/python2.7', '/scratch/hruiz/anaconda2/lib/python2.7/plat-linux2', '/scratch/hruiz/anaconda2/lib/python2.7/lib-tk', '/scratch/hruiz/anaconda2/lib/python2.7/lib-old', '/scratch/hruiz/anaconda2/lib/python2.7/lib-dynload', '/home/hruiz/.local/lib/python2.7/site-packages', '/scratch/hruiz/anaconda2/lib/python2.7/site-packages/Sphinx-1.4.1-py2.7.egg', '/scratch/hruiz/anaconda2/lib/python2.7/site-packages', ... and a bit more (cant post all of it). Is there any useful information? :) – HCRuiz Jul 22 '16 at 15:52
  • If anaconda is installed, then all the python packages should import from .../anaconda2/lib/python2.7/....., However, I see you import error shows that you are importing from other directory. Please try "conda install ipython", then the notebook may use anaconda's ipython. You can also use "which ipython" to certify that(the output should be ..../anaconda2/bin) – Tian Zhang Jul 22 '16 at 17:54
  • Thanks again @TianZhang! I tried the `conda istall ipython` and it says: # All requested packages already installed. # packages in environment at /scratch/hruiz/anaconda2: ipython 5.0.0 py27_0 However, the `which ipython` doesn't give me the expected .../anaconda2/bin. Instead I get /usr/bin/ipython... this must be the problem right? Is there an easy way out? can I change that path? how come the `conda install` doesn't solve this? Should I uninstall? – HCRuiz Jul 25 '16 at 18:55
  • At the end I reinstalled the whole Anaconda and removed the old directory... I though this is a solution, but I still get the same mistake! Numpy is still not being imported! if anyone knows how to change the paths to ipython and python s.t. they are "aligned" with the anaconda environment that would be great. I have no root privileges so I couldn't have changed the "header" (or I don't know what is the line with #! called?) to target the right file, like [here](http://stackoverflow.com/questions/9386048/ipython-reads-wrong-python-version). Please, if someone could help me with this! – HCRuiz Jul 27 '16 at 18:55

2 Answers2

2

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/

bfontaine
  • 18,169
  • 13
  • 73
  • 107
Jazz
  • 445
  • 2
  • 7
  • 22
1

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!
Community
  • 1
  • 1
HCRuiz
  • 65
  • 10