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

后端 未结 17 1966
再見小時候
再見小時候 2020-12-23 20:35

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.

17条回答
  •  长情又很酷
    2020-12-23 20:53

    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)
    

提交回复
热议问题