notebook: Import on Jupyter notebook failed where command prompt works.
Hi,
I am new to Python and Anaconda. I installed anaconda and install Scipy. When I try import scipy in the Python in command prompt on the Anaconda prompt, it works fine as below
[Anaconda3] C:\Users\me>python
Python 3.5.1 |Anaconda 4.0.0 (64-bit)| (default, Feb 16 2016, 09:49:46) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy
>>>
But when I use the same in the Jupyter notebook, I am getting -
ImportError Traceback (most recent call last)
<ipython-input-3-4dc45f4c0083> in <module>()
----> 1 import scipy
ImportError: No module named 'scipy'
Please let me know how to solve this issue.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 78
- Comments: 63 (13 by maintainers)
Usually that indicates that the notebook is running with a different Python or in a different environment from Python in the command prompt. Check
sys.executable
to see which Python it’s running in, andsys.path
to see where it’s looking for imports.try a
conda install ipykernel --name Python3
,python -m ipykernel install
. That will likely fix the notebook can see your Python 3 kernel. Then create anew
>Python3 notebook
from the dashboard.Hi, same issue here. Another approach is to install jupyter lab (or jupyter notebook) with “conda install -c conda-forge jupyterlab” after the environment’s activation; I mean, inside the environment, so that the jupyter lab runs on this environment and not on root. May be it’s not so much elegant, but is another way and works.
You can manipulate
sys.path
inside Python, e.g.It can also be affected by the
$PYTHONPATH
environment variable when Jupyter is started.To install package in jupyter notebook use following instructions: https://www.datadivein.com/2019/01/how-to-install-python-package-in.html
When I switch to Python 3 kernel, it still shows /usr/bin/python, which is python2.
So I had to run the following to make everything work
@nikhilrsharma I create a virtual environment in anaconda, then I solve this problem. https://uoa-eresearch.github.io/eresearch-cookbook/recipe/2014/11/20/conda/
After installing the virtual environment, every time when you open the terminal: you should command:
$ source activate _yourEnvName_
then run the jupyter notebook on your virtual environment. command:
$ jupyter notebook
If you want to pip install any package, you should install 2 times: the first one is in the terminal:
$ pip install something
the second time is to enter the virtual environment:$ source activate _yourEnvName_
and$ pip install something
solved it, in my case
https://ipython.readthedocs.io/en/stable/install/kernel_install.html
Use
--help
and look at the informations:A
--user
flag is available. Or, if you know what your doing, usesudo
to install with administrator permission.This might work for you.
Here is a short snippet that should generally work:
import sys !{sys.executable} -m pip install scipy
first use conda install nb_conda_kernels to set jupter notebook’s envirnment second change kernel to choose the environment
@pswpswpsw I do that… but do not looks to be my case (by the way the problem is with jupyterhub, not with jupyter, where is working)
sys.executable: /opt/anaconda3/bin/python sys.path: [‘’, ‘/opt/anaconda3/lib/python36.zip’, ‘/opt/anaconda3/lib/python3.6’, ‘/opt/anaconda3/lib/python3.6/lib-dynload’, ‘/opt/anaconda3/lib/python3.6/site-packages’, ‘/opt/anaconda3/lib/python3.6/site-packages/Mako-1.0.7-py3.6.egg’, ‘/opt/anaconda3/lib/python3.6/site-packages/IPython/extensions’, ‘/home/mazzitel/.ipython’]
just upgrade your jupyter notebook :
pip install --upgrade pip pip install jupyter
https://github.com/udacity/P1_Facial_Keypoints/issues/13#issuecomment-462085023
I was having the same problem. I also have the Anaconda navigator installed. I solved the issue from there.
This solved my issue