Jupyter running wrong python kernel #270
Comments
Can you check |
@takluyver off course, as you thought there was an override of the kernels. The output of Available kernels:
python3 /home/damejia/.local/share/jupyter/kernels/python3
python2 /usr/local/share/jupyter/kernels/python2 The kernel for python3 located in {
"argv": [
"python",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "Python 3",
"language": "python"
} So it called the wrong python version ( Available kernels:
python2 /usr/local/share/jupyter/kernels/python2
python3 /usr/local/share/jupyter/kernels/python3 And under a Python3 kernel in Jupyter the output of, import sys
sys.version baheves as expected, '3.5.3 (default, Jan 19 2017, 14:11:04) \n[GCC 6.3.0 20170118]' I'm not sure why this happened, I've been using Jupyther for about a year without problems so far. I hope this thread can help anyone. I guess It's closed |
@minrk could this be a result of trying to install the kernelspec as a data file in the Python package installation? I notice that it's using the new generic |
Well... I'm not sure. how can I test this? |
Yes, this is a result of the data-files installation. One solution is to hardcode handling of 'python2' or 'python3'. Another would be to change the kernelspec name to 'python' and call it Python (default), rather than specify the version (which probably makes more sense to most people, anyway). |
I think is a sensible idea. |
I had the same issue. In addition moving /home/myname/.local/share/jupyter/kernels/, I found that I needed to edit the two kernel.json files under /usr/local/share/jupyter/kernels/. In each of these, I changed "python" to explicitly-named python2 or python3 kernels. That fixed the problem for me. |
Quick update Hi everyone, i'm writing this update since it could help diagnose the problem. Linux ibuki 4.11.0-1-amd64 #1 SMP Debian 4.11.6-1 (2017-06-19) x86_64 GNU/Linux Module Versions So far, the versions installed are, Jupyter version 4.3.0 (via PIP3) Once the installation was made via Solution Proceeded to install the corresponding kernel as root with the command, |
Folks, just for adding a bit of information. I've been with this kind of problem with Julia notebooks for months. Running Mac OS X. I had installed in succesion Julia 0.4.5, 0.5 and 0.6, from the OSX installers. I wiped 0.4.5 and 0.5 out completely (so I think). Yet I would start a Julia notebook and it would look for Julia 0.4.5 without giving me any choice. After reading this thread I verified that I had 3 folders still were around:
It is weird that I have some of these in ~/Library and some in ~/anaconda. In my view this is the Julia installation by package, the anaconda installation by package, and some macports that I have installed (not sure about this one) Anyway. I deleted these folders
and things seem to work perfectly now. |
I also encountered a similar error. Jupyter notebook installation in my Ubuntu 17.04 cloud machine had issues selecting the right kernel. This is what I did to solve this issue. Step 1: $python2 -m pip --version $python2 -m pip install ipykernel For Python3: $python3 -m pip --version $sudo python3 -m pip install ipykernel Step 2: For Python2:
For Python3:
To get the list of available kernels: $jupyter kernelspec list The output for me was: Step 3: For Python2: Eg: { For Python3: { Step 4: |
Thanks @rahulremanan, as you suggested, I just changed {"argv": ["python",... ]} to {"argv": ["python3",... ]} and it worked. I'm not sure how it got set incorrectly, since it was fine before I upgraded jupyter notebook. |
I'm having a similar problem on binder.
I've also tried replacing {
"display_name": "Python 2",
"language": "python",
"argv": [
"python",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
]
} Strangely, when I run the exact same command in the terminal on the binder instance itself, the {
"display_name": "Python 2",
"language": "python",
"argv": [
"/usr/bin/python2",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
]
} Any idea how to fix this in the binder setup? |
You probably want to ask that on a binder repo, also you should not need to do that on a binder, it should install the kernel automatically. |
I should probably have said that I'm using binder with the (default) Python 3 kernel. And I wanted to install a Python 2 kernel manually on top of that. |
@mgeier Can you post the full output for the following:
|
When you do |
@takluyver It tells me:
This is the right directory, but the file doesn't seem to be changed, it's the same generic version (using If I add
|
I wonder if there's something special binder does when building images that overrides the kernelspec file you created. @choldgraf @yuvipanda ? |
hey @mgeier - have you tried using a |
This is the requested output when running the commands from
No, I haven't tried |
$ jupyter kernelspec list --json $ stat /usr/bin/python I explicitly installed this with python3, and even Jupyter knows it's python3 $ sudo find / -iname 'kernel.json' Yet, it completely ignored the fact that a python3 interpreter was used, and instead tries to use 2.7. Changing argv[0] to the correct path (/usr/bin/python3) in the kernel.json file fixed this (well maybe, I still get an error in Atom/Hydrogen but the output indicates the kernel started). |
@yuvipanda any ideas on #270 (comment) ? this feels like a repo2docker bug to me if the |
opened up binder-examples/python2_with_3#1 to see if we can get a prototype of python 2 within 3 working |
Good news everyone! Just for reference, some more details on what I tried and what worked for me in the end: I used a I used an
And I used this
|
Just FYI that there's now a working solution in https://github.com/binder-examples/python2_with_3 that uses |
I think the most recent problems are due to me accidentally publishing a universal wheel for ipykernel on December 6th. cf ipython/ipykernel#288 (comment) |
This is still an open and annoying problem - I have two python 3.6 environments set up for different projects (that is, after all, the whole point of having conda environments in the first place). It seems that the kernelspec will only allow one of them to be the python 3.6 kernel. That seems like an architectural mistake - each environment should know about the kernels associated with it. Or am I mistaken? Is there a way to handle multiple python versions aside from manually modifying the kernel file each time (ugh...)? |
If you want to use kernels from conda environments, you can install a package called something like nb_conda_kernels which provides kernels based on conda environments. |
Or you can install a different kernelspec file for each environment (i.e. use names other than |
this looks like a similar issue but on Windows |
Same issue - changing the default on Mint to 3.6 from 2.7 broke Jupyter as described. @rahulremanan's solution worked for me - editing the kernel.json file to point directly at python 2.7 and python 3.6. Checked separate kernels in the same run copy of Jupyter and the outputs are now in line with expectation. |
Actually this solution helped me. I followed exactly and got resolved. |
Just ran into what I think is the same problem on Windows.
When I run |
Maybe try the AnacondaNavigator go to "Environments" and open a Jupyter Notebook by klicking on the "Run Button" (Green Recktangle) of your desired Python Version. That worked just fine for me. |
I also just ran into this error on the new(ish) Google Cloud AI Platform Notebooks. In both the Tensorflow 1.x and the Python quickstart frameworks, despite having the Python 3 Kernel selected, an error was thrown because the notebook was using python 2.7 instead. Reporting this here just for awareness that this issue is affecting that platform as well. |
I have the same issue... |
Me too... |
Thank you @takluyver . Using his suggestion and also sys.executable showed that my kernel was pointing to a python.exe in the wrong virtual environment. Once I updated the kernel.json for the environment I wished to use to point it to the python.exe in the correct environment my issue was resolved. That and ensuring that ipykernel libary was installed in the env. I got myself into this situation because I am still learning Jupyter Lab and how it is set up. |
Same thing in a Ubuntu 18.04 (bionic) container. Executed as unprivileged user
Executing the same command as root produces
|
It Works |
Does anyone know how to start To be more specific, I am looking for one of the following:
|
@takluyver I followed the steps as written in this blog: https://medium.com/@nrk25693/how-to-add-your-conda-environment-to-your-jupyter-notebook-in-just-4-steps-abeab8b8d084. It was pretty easy and worked. |
Hi everyone, I want to report that Jupyter is loading the wrong Kernel
My machine is a Debian Testing,
Linux 4.9.0-3-amd64 #1 SMP Debian 4.9.30-1 (2017-06-04) x86_64 GNU/Linux
Python2.7 is installed by default, Python3 was installed from repositories, but I'm not sure if it comes by default with the system too. Jupyter and Ipython where installed via Pip (Pip was installed from the repositories)
Module Versions
Installed via pip with dependencies
pip install -U jupyter ipython
pip3 install -U jupyter ipython
So far, the versions installed are,
Proceeded to install the corresponding kernels as root with the commands,
ipython kernel install
ipython3 kernel install
Which seemed to work since Jupyter recognizes both kernels
And at the location
/usr/local/share/jupyter/kernels
there's this tree architectureWith the relevant contents,
I try to program with Python3 standard since 2.7 is old, so Installed a module I wanted to use by means of
pip3 install module_name
. The module worked with python3 console and Ipython3 console, but when I tried to implement the code inside a Jupyter notebook (with kernel Python3) and I got an error telling that the module wasn't available. After being unable to solve the problem I installed the module with pip2 and suddenly it was available at the Jupyter notebook (with kernel Python3) so I performed a simple check of the version of the running kernel under Jupyter,As you can see, it says that the kernel is Python3, but the call to
sys.version
(from the modulesys
) still shows that the running kernel is Python2.7. I don't know what's going on, even resetted Jupyther's configuration withjupyter notebook --generate-config
and the issue remains unsolved, that's why I decided to post here.On the other hand, calling the deprecated form
ipython3 notebook
produces the desired result,Wath am I missing?
The text was updated successfully, but these errors were encountered: