I have already installed Jupyter notebook in my ubuntu 16.04 machine. In jupyter notebook there is by default python installed. Now I want to use R from jupyter notebook.
Adding this for anyone, who googling and getting stuck on this issue may benefit from this simple learning. I got the same error, as above, followed the instructions above (while launching R in Terminal):
IRkernel::installspec()
Error in IRkernel::installspec() :
jupyter-client has to be installed but “jupyter kernelspec --version” exited with code 127.
In Bash I ran:
Mac-Pro:~ $ jupyter kernelspec --version
-bash: jupyter: command not found
Duh, I had no Jupyter installed. Install Jupyter (on mac, using brew) with: brew install jupyter
. Installation instructions for other OS's can be found here.
All now working fine.
I don't use conda - I have python virtual env and R installed.
I don't know if it matters but I'm running on ubuntu for windows (WSL) (might be the cause of my error, might be unrelated).
In the console, it recognized jupyter. Inside R console I installed IRkernel but IRkernel::installspec() gave me the error above (didn't recognize jupyter).
I couldn't find a solution that worked, so I am writing here what solved it for me.
I found the internals of installspec here.
Check before hand where is your jupyter installed with which jupyter
and run R from command line.
Then, run the following code (adjusted from the link above):
srcdir <- system.file('kernelspec', package = 'IRkernel')
tmp_name <- tempfile()
dir.create(tmp_name)
file.copy(srcdir, tmp_name, recursive = TRUE)
spec_path <- file.path(tmp_name, 'kernelspec', 'kernel.json')
library(jsonlite)
spec$argv[[1]] <- file.path(R.home('bin'), 'R')
spec$display_name <- 'R'
write(toJSON(spec, pretty = TRUE, auto_unbox = TRUE), file = spec_path)
args <- c('kernelspec', 'install', '--replace', '--name', 'ir', file.path(tmp_name, 'kernelspec'))
system2('/path/to/jupyter', args) <--- here you copy paste the path you got earlier with pwd
unlink(tmp_name, recursive = TRUE)
I am running Ubuntu 18.04.4 with R installed in /usr/bin/R and Python in /home/ubuntu/anaconda3/bin/python. I ran into a number of path related problems when trying to tell Jupyter where to find the kernel for my R installation. Regardless of how I ran R the IRkernel::installspec() would not work in R. I found success by making the connection using jupyter kernelspec from the command line. Specifically this is what worked for me.
From within R:
install.packages("devtools")
devtools::install_github("IRkernel/IRkernel")
system.file('kernelspec', package = 'IRkernel')
The last line should give you the location of Jupyter will need to find the kernel. Mine was /home/ubuntu/R/x86_64-pc-linux-gnu-library/4.0/IRkernel/kernelspec
From the command line:
jupyter kernelspec list
(run this to be
sure that jupyter is in your path, you should see information about
the current available kernels.jupyter kernelspec install /home/ubuntu/R/x86_64-pc-linux-gnu-library/4.0/IRkernel/kernelspec --name 'R' --user
(you will use path that you received while working in R which could be different)jupyter kernelspec list
(this list should now include R)Assume that you have already run R
in the terminal. You can first call library('IRkernel')
, press Enter, then call installspec()
or installspec(user=FALSE)
.
For me, simply calling IRkernel::installspec()
will always raise the error you mentioned in your question. I don't know why what I did solved this problem on my centos server.
I had the same issue; I added the following in the ~/.bashrc (and source
) and then tried running IRkernel::installspec()
and it worked:
export PATH="~/anaconda3/bin:$PATH"
On some Windows systems you may not succeed even if you run R from cmd / powershell. That's the case on my machine. My workaround is to run R from Anaconda Prompt (if you installed Jupyter via Anaconda). You may need to specify the full path if R is not on your PATH
.
I think this is some problem related to the PATH
, however I had no luck adding Anaconda\Lib\site-packages\jupyter_client
to my system PATH
.