简体   繁体   中英

Kernel Error in R Notebook using Jupyter Notebook

I am trying to use R within the jupyter notebook.

I went to my R shell and ran

install.packages(c('rzmq','repr','IRkernel','IRdisplay'),
             repos = c('http://irkernel.github.io/', getOption('repos')))
IRkernel::installspec()

Then I loaded up my ipython notebook and created a new notebook using the now available R extension. How ever when I access the notebook I run into this kernal error:

Traceback (most recent call last):
  File "C:\Users\Nina Kate\Anaconda3\lib\site-packages\IPython\html\base\handlers.py", line 394, in wrapper
    result = yield gen.maybe_future(method(self, *args, **kwargs))
  File "C:\Users\Nina Kate\Anaconda3\lib\site-packages\IPython\html\services\sessions\handlers.py", line 53, in     post
    model = sm.create_session(path=path, kernel_name=kernel_name)
  File "C:\Users\Nina Kate\Anaconda3\lib\site-packages\IPython\html\services\sessions\sessionmanager.py", line 66, in create_session
    kernel_name=kernel_name)
  File "C:\Users\Nina Kate\Anaconda3\lib\site-packages\IPython\html\services\kernels\kernelmanager.py", line 84, in start_kernel
    kernel_name=kernel_name, **kwargs)
  File "C:\Users\Nina Kate\Anaconda3\lib\site-packages\IPython\kernel\multikernelmanager.py", line 112, in start_kernel
km.start_kernel(**kwargs)
  File "C:\Users\Nina Kate\Anaconda3\lib\site-packages\IPython\kernel\manager.py", line 240, in start_kernel
**kw)
  File "C:\Users\Nina Kate\Anaconda3\lib\site-packages\IPython\kernel\manager.py", line 189, in _launch_kernel
return launch_kernel(kernel_cmd, **kw)
  File "C:\Users\Nina Kate\Anaconda3\lib\site-packages\IPython\kernel\launcher.py", line 202, in launch_kernel
proc = Popen(cmd, **kwargs)
  File "C:\Users\Nina Kate\Anaconda3\lib\subprocess.py", line 859, in __init__
restore_signals, start_new_session)
  File "C:\Users\Nina Kate\Anaconda3\lib\subprocess.py", line 1112, in _execute_child
startupinfo)
    FileNotFoundError: [WinError 2] The system cannot find the file specified

I was having exactly the same error in Windows 7. I added R to PATH environment variables and I was able to run it on shell but I was still having the kernel error in Jupyter.

The Kernel started working when installed system wide using:

IRkernel::installspec(user = FALSE)

instead of the first installation option:

IRkernel::installspec()

Note that it is necessary to set both parameters, the PATH variable and the R system wide install.

You probably missed the warning up top about a missing index in the irkernel repo:

Warning: unable to access index for repository http://irkernel.github.io/src/contrib:
   cannot download all files

The new installation steps worked for me (in R 3.3 console):

install.packages('devtools')
devtools::install_github('IRkernel/IRkernel') # IRkernel-master.tar.gz
IRkernel::installspec()  # register kernel in the current R install
IRkernel::installspec(name = 'ir33', displayname = 'R 3.3')  # ir32, R 3.2

When you restart jupyter notebook , an "R 3.3" entry should appear in the list of kernels.

If using Windows 10 and not using Anaconda, then try this;

Review your existing kernel file with Notepad. File is located:

~ AppData\\Roaming\\Jupyter\\kernels

This file will show the version of R that was used when Jupyter was installed. If you changed or upgraded the version of R currently being used, then R Kernel will not work in Jupyter.

R Studio -> Tools -> Global Options -> Change , to review versions of R installed on PC. If the current version of R is different than the version in the kernel file, select that other version of R. Close R Studio and reopen to verify version being used. Close R Studio and open Jupyter Notebook and select the R kernel. R kernel should now work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM