notebook: Unable to import installed libraries
In a new conda environment, I run conda install ipython-notebook and then conda install matplotlib. I launch the notebook using jupyter notebook as usual and everything looks okay. However, when I’m trying to import matplotlib (import matplotlib.pyplot as plt or simply import matplotlib) I get ImportError: No module named matplotlib.pyplot and an error in the terminal:
[IPKernelApp] ERROR | No such comm target registered: ipython.widget
The same happens when I install pandas. What did I do wrong? Running conda list shows that both packages are installed in the current environment.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 59 (20 by maintainers)
I changed my kernel spec to just
pythonwithout the absolute path.Is
sys.executablewhat you expect?That looks okay. I forgot to add that matplotlib and pandas are working from the ipython console, but the qtconsole and the notebook are having this same issue.
UPDATE:
I tried that in the console, which is giving the correct environment. However, running the same in the notebook actually gives the wrong environment. Why? The other environment is not active right now and doesn’t have matplotlib or pandas listed as installed.
Take a look at your kernelspec. The path for calling python will probably point to the wrong environment.
my environment is mac and python3 i also on jupyter can not import matplotlib
on jupyter run sys.executable is ‘/Library/Frameworks/Python.framework/Versions/3.5/bin/python3’ on terminal run sys.executable is ‘/Users/abc/anaconda/bin/python3’
so what can i do to solve the problem ?
and just rm jupyter-kernelspec seemed can not work
The location of the kernel spec depends on your system. Should be in one of these:
I am sure @minrk can explain this better.
Many thanks. I think it’s sorted now.
the nb_conda extension seems to work. Are there any particular confusions I should watch out for?
This value of
sys.executable:Means that your Python 3 kernel is running in your conda root environment, not the ipykernel_py3 environment you created. If it was in that environment, it you would see something like
/Users/Chris/anaconda3/envs/ipykernel_py3/bin/python.Oh, okay. In any case, @juhasch’s solution is working perfectly.
In Ubuntu to find the kernel spec file and change it, in my case:
sudo nautilus' to open the folder with root privilege, then navigate to: /usr/local/share/jupyter/kernels/gpu37 then open kernel.json change the wrong path to the correct one. The correct one should be the return by running the correct python versionpythonimport sysprint(sys.executable)` copy the correct python path to the kernel.js file and saveHi @takluyver ,
A problem seems to have occured based on this core kernel path issue , I think.
If I run
jupyter kernelspec listin root environment, I now get:and if I run
In Jupyter notebook and python interpreted running on my Python 3 kernel, I get:
When installing packages etc. I have gone into:
before using conda install to add new packages.
But I am having a problem now with pandas-datareader. I installed using conda install within the ipykernel_py3 environment, with:
Which seemed to work, and with
conda list, I see:But when I try to import pandas_datareader (the correct import name, based on the documentation here within either a Jupyter notebook on the Py3 kernel, or the interpreter
import pandas_datareader as pdrI get
ModuleNotFoundError: No module named 'pandas_datareader'Which I don’t understand.
This install approach has worked for other modules (e.g. seaborn, which seems to be working fine).
Can you help me understand why this module isn’t working, or being recognised?
Many thanks