55

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.

To do so I followed IRkernel installation link and run below commands:

install.packages('devtools')

devtools::install_github('IRkernel/IRkernel')

But when I run IRkernel::installspec() command it shows below error:

jupyter-client has to be installed but “jupyter kernelspec --version” exited with code 127

I am now confused why this error occurs.

5
  • Did you run it from the terminal?
    – leah
    May 21, 2017 at 14:05
  • Yes I run this command from terminal. May 22, 2017 at 8:19
  • is jupyter on your path?
    – leah
    May 22, 2017 at 8:28
  • 1
    I had the same issue. Solved mine by running R in the console as Admin. Apr 17, 2018 at 21:18
  • @ShalomJohn Your comment is the only thing that helped me! It should be an answer.
    – Logan Yang
    Dec 4, 2018 at 20:16

24 Answers 24

46

Running this command from RStudio will show this error. When you run this command from command line/ terminal then everything will be fine.

So just type R from your command line.

Then Run below commands:

install.packages('devtools')

devtools::install_github('IRkernel/IRkernel')

enter image description here

IRkernel::installspec()
2
  • 23
    nope, I have the issue when running directly the R console Jul 8, 2019 at 6:19
  • You saved my day
    – Mysterio
    Mar 28, 2020 at 19:07
35
  1. If Anaconda is installed and the Jupyter-Notebook with it (should be the standard install), open up the Anaconda prompt, not the Windows command prompt or the Anaconda Navigator
  2. Look up the executable of R (not Rgui or Rstudio), it should be somewhere like C:\Program Files\R\R-3.5.1\bin and remember the path typing cd C:\Program Files\R\R-3.5.1\bin and start R by typing R
  3. typing IRkernel::installspec()
  4. Now you can start an R kernel within Jupyter-Notebook
1
  • 1
    Thanks a lot. This worked. Can you explain why it works from anaconda prompt and not from windows prompt
    – Dayne
    Aug 2, 2020 at 14:29
17

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.

3
  • 5
    In my case of Windows10, C:\Users[user name]\Anaconda3\Scripts shoud be added to system PATH.
    – JKim
    Mar 23, 2018 at 14:15
  • This also worked for me, although my path was C:\ProgramData\Anaconda3\Scripts.
    – capm
    Jul 19, 2018 at 20:42
  • this worked for me on my win 10 laptop. On win 7 desktop it was not needed. Might be how anaconda is installed on 7 vs 10?
    – beginner_
    Aug 3, 2018 at 10:30
13

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:

  1. inspect the path that you receive when you were in R. There should be a .json file in it.
  2. jupyter kernelspec list (run this to be sure that jupyter is in your path, you should see information about the current available kernels.
  3. 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)
  4. jupyter kernelspec list (this list should now include R)
  5. restart jupyter
4
  • This worked for me, thanks. PS: I installed Jupyter using pip3, not Anaconda.
    – Lfppfs
    Jul 5, 2021 at 13:48
  • This worked for my in Parallels virtual box. Thank you.
    – eod
    Apr 28, 2022 at 21:42
  • This worked for me in Ubuntu 20.04. I also installed Jupyter using pip.
    – user15277323
    Jun 14, 2022 at 3:01
  • Finally got this working using your instructions, thx (Linux Mint 21.2)!
    – aimfeld
    Nov 9 at 8:25
10

I have solved with this:

sudo ln -s /home/'my user name'/anaconda3/bin/jupyter /usr/bin/jupyter

3
  • That doesn't look like a great fix to me. Is that path accessible to other users on the system who want to use jupyter from /usr/bin? Can't you just add your ~/anaconda3/bin path to your PATH in your .profile or .bash_profile? (Doesn't that happen automatically?)
    – Rup
    Mar 14, 2018 at 12:08
  • Hello Rup. This link the two directions. It tells R where to find the Jupyter runner and there having the kernel. Once Jupyter has the R kernel I think it could be open to every user. Mar 15, 2018 at 14:14
  • Try Making a Link before reinstalling software
    – mccurcio
    May 1, 2018 at 17:46
7

I tried to install IRkernel on my Windows machine. I experienced a similar problem when I ran from within R:

> IRkernel::installspec(user = FALSE)
Error in IRkernel::installspec(user = FALSE) : 
  jupyter-client has to be installed but “jupyter kernelspec --version” exited with code 1.

I did not use conda to install Jupyter on my machine, but pip. I have some programmes installed which use python under the hood. It means that I have more than one Python instance on my machine and more Jupyter instances too. To be sure I was referencing the right Jupyter instance, I did this:

> setwd('C:/usr/lib/Python36-32/Scripts')
> IRkernel::installspec(user = FALSE)
[InstallKernelSpec] Installed kernelspec ir in C:\ProgramData\jupyter\kernels\ir

Besides Python, I can now also use R within my notebooks.

1
  • This works for me on windows with python environment via venv. 1. devtools::install_github('IRkernel/IRkernel'). 2. setwd("c:/path/to/python/environment/Scripts"). 3. IRkernel::installspec(user = FALSE)
    – Renhuai
    Dec 20, 2020 at 3:03
6

Here a way to overcome this problem. I have installed IRkernel with anaconda in my mac (I guess is the same on Linux). The below command also works in windows to be run on Anaconda shell and pressing y after a y/n prompt (you can also refer https://medium.com/@kyleake/how-to-install-r-in-jupyter-with-irkernel-in-3-steps-917519326e41)

I typed:

conda install -c r r-irkernel

Then I started started R typing:

R

Finally, I have install the kernelspec to tell Jupyter about IRkernel, with the option user=FALSE for installation in the global environment:

IRkernel::installspec(user=FALSE)

Hope it helps!

1
  • This worked for me! Windows 10 running Anaconda + Vscode (Jupyter notebook)
    – Haider
    May 15 at 19:04
4

In windows 10 sys you just move the 3 files in your R library (install 'IRkernel' before this step) enter image description here to your jupyter-lab "ir" path enter image description here

Hope it helps u!

4
  • I don't use anaconda. I just use pip! It's simple!
    – Hao Liang
    Feb 10, 2021 at 7:21
  • This also works well under Linux and for "JupyterHub" - I had to copy it from R's library to /opt/tljh/user/share/jupyter/kernels/ and it worked like a charm
    – shghm
    Oct 7, 2021 at 7:09
  • this works for me: Windows 10, pip installed jupyter. Thank you very much!
    – pengchy
    Jan 23 at 12:25
  • Thank you so much! It works for me on windows 10 using pip.
    – ChristHope
    Oct 5 at 21:02
4

I came up with the same problem and solved it with ease following these steps

pc specs: macOS version 10.14.6

  1. make sure R is installed if not find here how to.
  2. make sure you have jupyter notebook installed if not find that here how.
  3. Go to the terminal or use Launchpad to launch R, then install following package:devtools::install_github('IRkernel/IRkernel').
  4. find out the where its installed using:system.file('kernelspec', package = 'IRkernel') and use the path (mine was : /Users/ali/Library/R/4.0/library/IRkernel/kernelspec) you get here in the commond below.
  5. now go to the terminal again and type this : jupyter kernelspec install /Users/ali/Library/R/4.0/library/IRkernel/kernelspec --name 'R' --user.
  6. Then the last thing is to check the kernal list and restart notebook using cmd 4 and 5 from @Bryan Prazen above.

enjoy !!

1
  • I installed r in brew, then did install.packages('IRkernel') in rstudio, and I had to do this command on step 5: jupyter kernelspec install /usr/local/Cellar/r/4.1.2/lib/R/library/IRkernel/kernelspec --name 'R' --user Mar 21, 2022 at 18:34
2

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.

1
  • 1
    Similar issue here on Windows (I think it might be because I chose Miniconda). But I did have to run "conda install jupyter_client" to get installspec() to work.
    – Ben Ogorek
    Feb 9, 2019 at 14:05
1

I had the same error but the fix was different:

Make sure you also have anaconda install on your system! (or at least jupyter) https://conda.io/docs/user-guide/install/index.html

1

I had the same error, but in my case, I have jupyter installed in a virtual environment, so I had to start R after installing the virtual environment in order for IRkernel::installspec() to succeed.

1
  • wow this was the answer I required. I forgot that I installed jupyter in virtual env and I was trying hard with all the other solutions and after looking your answer only then I realized my mistake.
    – mockash
    Mar 2, 2020 at 11:18
1

I had the same error while trying to install my environment as kernel in Jupyter. First I had created a new environment, installed R, IRkernel and devtools from within conda prompt, then runned R typing R from the prompt and typing

IRkernel::installspec(name = 'myenvname', displayname = 'myenvname')

I had the same error. I solved simply in this way:

conda install -c anaconda jupyter_client

And then retyping the previous code it just worked.

0
1

For mac users:

I came across the same problem. You should call IRkernel::installspec(user = FALSE) in the terminal through R. I solved it this way, and I bet you could do the same:

  1. Call R.home() in R console
  2. You shall get [1] "/Library/Frameworks/R.framework/Resources"
  3. Add /bin/R to path nlike this: /Library/Frameworks/R.framework/Resources/bin/R
  4. In terminal, paste this path /Library/Frameworks/R.framework/Resources/bin/Rand enter.
  5. Now you are using R in terminal. CallIRkernel::installspec(user = FALSE) And it shall be solved then.
0

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"
0

I had the same problem but none of the above solutions worked for me. I was using Debian 9 with the default versions of python and R. I had to delete installed programs and compile latest versions of both from source. For Python compiling I had to use this configuration https://github.com/sloria/TextBlob/issues/173

0

For Windows Users, After installing anaconda, you should restart your system so Anaconda prompt appears on start. After opening Anaconda Prompt enter

IRkernel::installspec()

This time it will works since I think restart 'cuz PATH of the system to be upgraded.

0

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)
0

I was installing jupyter notebook for R in linux and when I was adding IRkernel for jupyter then I got this same error. Then I install jupyter-client by using Linux terminal sudo apt-get install jupyter-client After this, no other error occurred.

1
  • sudo apt-get install jupyter-client Jun 20, 2021 at 10:22
0
  1. Check if you have installed: R language, Python&Anaconda which automatically comes with jupyter.

  2. Check if your jupyter is working by opening it from the (just regular windows) command prompt: jupyter-lab. This should open jupyter environment in browser and if you are still unsuccessful, shows only python.

  3. Run the code directly in the R console, not in an R interface like R studio. Find this by searching for R [version number] on your PC: example R 4.2.1.

  4. RUN R CONSOLE AS ADMINISTRATOR (credit: ShalomJohn)

  5. Run the code previously suggested in different answers:

     install.packages('devtools')
     devtools::install_github('IRkernel/IRkernel')
     IRkernel::installspec()
    
  6. If you look at the Jupyter-lab window, R should now show up next to Python

0

I gradually realise that the error message is the key answer. According to a similar error with code 1, I solved it only by installing the Jupyter client ... ...

1
0

Check your conda virtual environments.
For me, the IRkernel::installspec() was giving the same error until I remembered that my jupyter package was only installed in one of my conda environments. So I just activated it with

conda activate My_environment_name

in Anaconda prompt (I opened it as administrator), and then the standard instructions worked.

0

I'm not sure the sequence was exactly precise in the order I'm going to type but it did work. So in case it helps someone:

If IRkernel::installspec() result in an error message like:

jupyter-client has to be installed but “jupyter kernelspec --version” exited with code 1

it may require prior installation of devtools. As explained in this other answer:

From Ubuntu cmd line (not from within R):

sudo apt install r-cran-devtools

And then update Jupyter and install Jupyterlab:

pip install --upgrade jupyter

pip3 install jupyterlab

Now try again from within R:

IRkernel::installspec()

-1

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.