Closed thirumalaipm closed 2 years ago
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, and sys.path
to see where it's looking for imports.
Thanks takluyver,
I see the difference. The path from the command prompt shows
sys.executable 'C:\Users\user\AppData\Local\Continuum\Anaconda3\python.exe'
Where as the notebook shows 'C:\Users\user\AppData\Local\Continuum\Anaconda3\envs\py35\python.exe'
I had installed py27 and py35 on my system. Can you please let me know how to change to path which is used in command prompt.
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 a new
>Python3 notebook
from the dashboard.
Hi, I'm encountering the same problem here. I've installed successfully tensorflow and anaconda on my Mac OS. Everything goes fine in spyder, while when programming in Jupyter notebook, some modules seem to be not exist and cannot be imported. "Error: no module name matplotlib, scipy....."
~~Then I checked the system and found: In spyder, sys.executable is "/Users/abc/anaconda/bin/python"; In Jupyter, sys.executable is "/Users/abc/anaconda/envs/tensorflow/bin/python" (no matter whether I activate tensorflow in terminal)~~
Both python version are 2.7.11. Now I want to change the python path in Jupyter to which spyder uses. Can anyone please tell me how to do this? Thanks a lot.
See separate issue: #1580
$ /Users/abc/anaconda/bin/python -m pip install ipykernel
$ /Users/abc/anaconda/bin/python -m ipykernel install
It works! Thank you so much for your help, really saved my life!
It works! Thank you so much for your help, really saved my life!
Happy coding !
I tried doing what Carreau suggested and although I was able to then import scipy it made it so I could now no longer import matplotlib which I could previously....
You have one Python environment with scipy installed but not matplotlib, and one with matplotlib installed but not Scipy. Whichever one you pick, you'll have to work out how to install the missing package into it, using conda or pip.
I have a similar problem. My problem is that when I launch my anaconda environment and access to Python script. the next line works well: from imgaug import augmenters as iaa but when I execute the same line in jupyter notebook or spyder(both in anaconda), the error occur.
In Python script, the sys.executable:'/home/lqq/anaconda2/envs/tfgpu/bin/python'
My jupyter notebook and spyder have same sys.executable:'/home/lqq/anaconda2/bin/python'
I use the command that @Carreau provide,but only the first one runs well. In second, the error message is: [Errno 13] Permission denied: '/usr/local/share/jupyter'
Use --help
and look at the informations:
$ /path/to/python -m ipykernel install --help
usage: ipython-kernel-install [-h] [--user] [--name NAME]
[--display-name DISPLAY_NAME]
[--profile PROFILE] [--prefix PREFIX]
[--sys-prefix]
Install the IPython kernel spec.
optional arguments:
-h, --help show this help message and exit
--user Install for the current user instead of system-wide
--name NAME Specify a name for the kernelspec. This is needed to
have multiple IPython kernels at the same time.
--display-name DISPLAY_NAME
Specify the display name for the kernelspec. This is
helpful when you have multiple IPython kernels.
--profile PROFILE Specify an IPython profile to load. This can be used
to create custom versions of the kernel.
--prefix PREFIX Specify an install prefix for the kernelspec. This is
needed to install into a non-default location, such as
a conda/virtual-env.
--sys-prefix Install to Python's sys.prefix. Shorthand for
--prefix='/Users/bussonniermatthias/anaconda'. For use
in conda/virtual-envs.
A --user
flag is available. Or, if you know what your doing, use sudo
to install with administrator permission.
Thank you @Carreau ! I had solved this problem! Eh,,,I just reinstall the imgaug under the anaconda environment,then,it worked OK,,,sounds like a joke,hahaha,,, Thank you for your sincerity!
Carreau, I have similar problem. I high light our old HDP version 2.4.2.0-258 on the screen below, but we have the new HDP version 2.6, Looks like jupyter pick up the sys.path automatically, where I can find this Jupyter sys.path and what this sys.path name so that I can change this sys.path and get the correct python package
Thannk you for your quick response
You can manipulate sys.path
inside Python, e.g.
sys.path.remove('/path/you/dont/want')
sys.path.append('/path/you/do/want')
It can also be affected by the $PYTHONPATH
environment variable when Jupyter is started.
Great, answers above. I just create symlinks between respective system path and anaconda installation of python, for e.g.
1. get system path !which python2; if the returned path is `/usr/bin/python2`
2. sudo ln -s /home/anaconda2/bin/python2 /usr/bin/python2
this helps me moving from different versions of the python and making the notebooks work consistently.
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.
i ran the following commands up above because it had up votes and it broke my ability to launch a jupyter notebook and killed that environment costing me hours of time to rebuild all the installs. Its unlikely someone will see this before they try it but in case they do
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 a new >Python3 notebook from the dashboard.
i have this error please help
ModuleNotFoundError Traceback (most recent call last)
The script jupyter-nbconvert.exe is installed in 'c:\users\moosa computers\appdata\local\programs\python\python36\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. how do i resolve this?
Following is outcome of my terminal window: (ComputerVision) MacBook:~ Mac$ python Python 2.7.3 |Continuum Analytics, Inc.| (default, Dec 20 2012, 09:57:39) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "help", "copyright", "credits" or "license" for more information.
import sys sys.executable '/anaconda2/envs/ComputerVision/bin/python'
Following is the output of jupyter notebook:
import sys sys.executable
'/anaconda2/bin/python'
I think issue is with virtualenv ComputerVision ..How to fix this ?
So what is the exact solution? I am working on a linux and can't find any documentation from the anaconda and jupyter community.
$ python
import sys sys.executable '/home/abb/anaconda3/envs/something/bin/python'
What are the next steps?
I was having the same problem. I also have the Anaconda navigator installed. I solved the issue from there.
This solved my issue
To install package in jupyter notebook use following instructions: https://www.datadivein.com/2019/01/how-to-install-python-package-in.html
sys.executable
sys. sys.executable '/Library/Frameworks/anaconda3/bin/python'
path sys.path ['/Users/macbookpro/PycharmProjects/PYTHONCODE', '/Library/Frameworks/anaconda3/lib/python37.zip', '/Library/Frameworks/anaconda3/lib/python3.7', '/Library/Frameworks/anaconda3/lib/python3.7/lib-dynload', '', '/Library/Frameworks/anaconda3/lib/python3.7/site-packages', '/Library/Frameworks/anaconda3/lib/python3.7/site-packages/aeosa', '/Library/Frameworks/anaconda3/lib/python3.7/site-packages/IPython/extensions', '/Users/macbookpro/.ipython']
i can't import it in jupyter..i need some help
solved it, in my case
conda install ipykernel --name {envname}
python -m ipykernel install --prefix=/anaconda3/envs/{envname} --name {envname}
https://ipython.readthedocs.io/en/stable/install/kernel_install.html
Using virtualenv or conda envs, you can make your IPython kernel in one env available to Jupyter in a different env. To do so, run ipykernel install from the kernel’s env, with –prefix pointing to the Jupyter env:
Solved it.
Run jupyter kernelspec list
in the terminal, or run import sys; sys.executable
in an opened jupyter-notebook to see which interpreter it is using, and then we can manually delete these interpreters. Jupyter will then automatically find the other default interpreters (the ones with the right packages correctly installed)
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.
works perfectly @Carreau
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 a new >Python3 notebook from the dashboard.
apart from the fact that I had to specify the specific python version.
i.e. 'python -m ipykernel install' changes to:
python3.7 -m ipykernel install.
As I have python3.7 installed on my machine.
Typing python alone reverts back to python2.7.
Thumbs up from me!!
just upgrade your jupyter notebook :
pip install --upgrade pip pip install jupyter
I have the same problem by importing ROOT CERN on centos with anaconda and jupyterhub perfectly woking on command prompt but not working in the notebook
ImportErrorTraceback (most recent call last)
in () ----> 1 import ROOT ImportError: No module named ROOT
following the idea of this post I have temporary solved the problem for python3 (default in my coda installation) by the following path added directly before calling the module
import sys
sys.path.insert(0, "/usr/local/root/build")
sys.path.insert(0, "/usr/local/root/build/lib")
sys.path.insert(0, "/usr/local/root/build/etc/notebook")
import ROOT
it' not clear to me how to make it permanent, any help?
I got @Carreau 's suggestion to work by doing:
python -m ipykernel install
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.
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
python2 -m pip install ipykernel python2 -m ipykernel install --user
python3 -m pip install ipykernel python3 -m ipykernel install --user
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.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
python2 -m pip install ipykernel python2 -m ipykernel install --user python3 -m pip install ipykernel python3 -m ipykernel install --user
@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']
first use conda install nb_conda_kernels to set jupter notebook's envirnment second change kernel to choose the environment
importError Traceback (most recent call last)
ModuleNotFoundError Traceback (most recent call last)
Here is a short snippet that should generally work:
import sys !{sys.executable} -m pip install scipy
$ /Users/abc/anaconda/bin/python -m pip install ipykernel $ /Users/abc/anaconda/bin/python -m ipykernel install
I have a similar issue here...
The paths are different, but one is in python3 and another is in python... I've tried:
/Users/shinyuwu/anaconda3/bin/python -m pip install ipykernel
/Users/shinyuwu/anaconda3/bin/python -m ipykernel install
But still not work for me :( Can anyone help me
I am also facing similar problem.
sys.executable at command prompt gives: "C:\Users\Public.DESKTOP-6RBQT7L\AppData\Local\Programs\Python\Python37-32\python.exe" and Jupyter Notebook gives "C:\ProgramData\Anaconda3\python.exe".
Not sure what am I supposed to do now. Which command should I use in Jupyter Notebook to install quandl in the folder of Jupyter Notebook?
python -m ipykernel install
Doesn't work for me. Says : "EnvironmentLocationNotFound: Not a conda environment: C:\Users\Public.DESKTOP-6RBQT7L.conda\envs\Python3". Don't know what to do now.
$ /Users/abc/anaconda/bin/python -m pip install ipykernel $ /Users/abc/anaconda/bin/python -m ipykernel install
I have a similar issue here...
The paths are different, but one is in python3 and another is in python... I've tried:
/Users/shinyuwu/anaconda3/bin/python -m pip install ipykernel /Users/shinyuwu/anaconda3/bin/python -m ipykernel install
But still not work for me :( Can anyone help me
Did it work for you? I am facing a similar issue.
@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
Thank You so much "takluyver"
$ /Users/abc/anaconda/bin/python -m pip install ipykernel $ /Users/abc/anaconda/bin/python -m ipykernel install
Thank you so much!!!!!!!!!!!
You are executing your notebook inside an Anaconda environment. Try the following:
conda install -n curr_env scipy
where curr_env is your Anaconda environment name.
Hi @thirumalaipm I had the same issue, this is what worked for me.
They both need to be the same.
In order to check whether you are having module installed. Type help('modules')
, and find the module you are trying to work with.
If it is listed there, it means it is installed.
Then there might be some ambiguity in your Python path or version conflict(mentioned at top) as I was having.
ModuleNotFoundError Traceback (most recent call last)
please I need assistance
As noted multiple times above, given things work in python directly and not from a kernel launched from the notebook server, this is most likely a difference in envs between the two python executables. Locate the kernel.json
file (using jupyter kernelspec list
) of the kernel you're launching and ensure the python used in the argv
stanza is the same as the python used from the command line.
Please check your version of syft
in each environment. If older than 0.2.1.a1 then the import should be from syft.frameworks.torch.federated
. If its a more recent version, then there might be an issue with the underlying torch installation - I don't know.
Also note that pip install syft
reverts both tornado (back to 4.5.3) and notebook (back to 5.7.8) installations - so beware!
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
But when I use the same in the Jupyter notebook, I am getting -
Please let me know how to solve this issue.