I have jupyter notebook installed, I also have R installed. Both work fine independently.
When I run jupyter with jupyter notebook, then try to open an ipynb file, I see
The only option in the dropdown is Python 3 (R is not an option).
Question
How do you open a jupyter notebook with an R kernel (on mac)?
Note
I tried jupyter notebook --runtime-dir /usr/local/bin/R but that was just guessing
Looks like the R kernel could be installed via pip?
Open any R session (e.g. in RStudio is fine, or open terminal/bash and type R to start an R session).
Install the kernel with:
install.packages("devtools")
devtools::install_github("IRkernel/IRkernel")
IRkernel::installspec()
Close and reopen the notebook and the R kernel will now be available.
If the R kernel does not appear as an option within a Jupyter notebook even after installing R, and one is using Anaconda, bringing up the conda prompt from the Start menu (Windows 10), and running the following commands may do the trick:
conda config --add channels r
conda install --yes r-irkernel
Credit to this post.
Related
Summary
Installed R kernel in Anaconda environment
Works with Anaconda's browser Jupyter notebook, but not VS Code.
Details
I am trying to set up VS Code to recognize my R kernel for use with Jupyter Notebooks. The steps I have followed are as follows:
Create a new R environment (via the Anaconda interface... Rstudio works just fine).
Using the command line interface with the above environment activated, ensure Jupyter is installed: conda install jupyter
Install irkernel: conda install -c r r-irkernel
Run R from command line and initialize irkernel:
R
> IRkernel::installspec()
Open VS Code and create a new notebook. Select the R kernel that appears, and run a basic commannd in the first cell: file.path(getwd())
These follow the steps here, and in other Stackoverflow posts (here and here).
Unfortunately, I cannot get the kernel to work. The above code in item 5 results in the following error:
Failed to start the Kernel.
The kernel died. Error: ... View Jupyter log for further details.
There is a copy of the log available here (should be visible to everyone). The notebook is available here (but is literally just the one line of code mentioned above).
My hypothesis is that IRkernel::installspec() installs the kernel in a different location than the conda environment. The kernel is installed in C:\Users\aaron\AppData\Roaming\jupyter\kernels\ir, while in VS Code the kernel selected is in C:\Users\aaron\.conda\envs\rstudio\lib\R\bin\x64\R (the environment name is rstudio).
However, when I open Jupyter notebook via the Anaconda interface (not VS Code... i.e. the browser version), everything works just fine. The same code (file.path(getwd())) returns the appropriate 'C:/Users/aaron'.
I am sure I have done something silly wrong, and appreciate your help in advance!
I have uninstalled and reinstalled Anaconda many times. I have tried:
Installing geopandas directly into the base (hangs, will not install)
Installing geopandas into the geo_env environment (works, but will not activate on the Jupyter kernel)
(By the way, I have also tried the microcondas environment and rolling back to the windows 32 bit environment, neither worked.)
Here's where I am now, and I am stumped:
Anaconda Prompt
I read the part about the Linking Jupyter kernelspec to Anaconda Python #2898 and it looks okay, picture below. https://github.com/jupyter/notebook/issues/2898
kernel.json
Which results in this: Disconnected kernel
I wanted to ask how to repair kernel connection for R in jupyter notebook,
I am able to run R in Rstudio and python in jupyter notebook, I used to write R in jupyter notebook but after some updates(I dont know what updates) R stop working in jupyter notebook.
I would like to ask for some advices - I would like to run it without reinstalling it
I also folled some question on stackoverflow and on google but it was not helpfull.
I attached images of what errors it returns
I did try: $ conda install -c r r-irkernel
I use conda python environment. I start the Jupyter lab following the steps below:
$conda activate <env_name>
$jupyter lab --no-browser --port=8080 &
Now, from a jupyter lab notebook, when I try to import feather (import feather), it fails with Module Not Found message.
From the jupyter lab notebook, if I execute the following, it shows me that feather is present:
! conda list | grep feather
Now, if I shutdown Jupyter Lab in the same VM and start Jupyter Notebook instead, feather gets imported successfully from the notebook.
$conda activate <env_name>
$jupyter-notebook --no-browser --port=8080 &
I see this discussion, but don't see a solution there.
Alternatively, check your path from within your Jupyter notebook vs on the command line. I found that appending the module paths to sys.path solved this exact issue.
All of the ~/anaconda3/envs/[env]/lib/python3.7* paths were missing in my case.
I have found a possible work around to avoid this issue. This is based on this answer.
From the conda environment (e.g. my_env), I can create a new Python 3 kernel (say, python3_custom). Now, this kernel will be associated with all the libraries installed in that conda environment.
$ conda activate my_env
(my_env)$ conda install ipykernel
(my_env)$ ipython kernel install --user --name=python3_custom
(my_env)$ conda deactivate
I come out of my_env or base environment. Then I start JupyterLab from the command prompt:
jupyter lab --no-browser --port=8080 &
Once I open my notebook now, I can select the kernel as python3_custom. Since in the associated conda environment (my_env), feather is already installed, I don't get the error "Module Not Found" any more.
I recently installed the Anaconda3 distribution and I want to have the R and Julia Kernels available besides Python. I use windows 10.
To install IJulia I installed the Julia language and follewed the steps indicated in the IJulia page; everything went fine.
To install the R kernel I used the command conda install -c r r-essentials in the anaconda command prompt, again, no problems. I also installed R.
When I launch the notebook the only available kernel is Python, the R and Julia kernels doesn't appear in the list, I have no clue why this since I got no errors in the installation of IJulia and IRKernel. Anyone could help?
After a fresh installation of Anaconda Distribution (either 2 or 3), following steps should be performed to achieve the desired kernels (R & Julia) on your notebook.
To install R on Anaconda(2/3) Jupyter Notebook :
Open 'Anaconda Command Prompt' & execute conda update notebook to update your Jupyter notebook to the most recent version.
Then install IRkernel by conda install -c r notebook r-irkernel
Now you may open R in your command prompt by running R.exe
Install all necessary R packages using the following lines in the R console by executing :
install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon', 'pbdZMQ',
'devtools', 'uuid', 'digest'))
devtools::install_github('IRkernel/IRkernel')
Finally, make the R kernel available to your Jupyter Notebook by executing:
Install only for the current user ➡ IRkernel::installspec()
For System-wide installation(all Users) ➡ IRkernel::installspec(user = FALSE)
To install Julia on Anaconda(2/3) Jupyter Notebook :
First, download Julia version 0.4 or later and run the installer. Then run the Julia application (double-click on it); the Julia Console with a julia> prompt will appear.
Now, for the most important step, open 'Anaconda Command Prompt' & execute where jupyter to see the actual path of your Jupyter Notebook. The output will be something like "C:\Users\JohnDoe\AppData\Local\Continuum\Anaconda3\bin\jupyter.exe"
Copy the above location and go to your Julia console. Now, execute the following respectively:
ENV["JUPYTER"]="C:\\Users\\JohnDoe\\AppData\\Local\\Continuum\\Anaconda3\\bin\\jupyter.exe"
Pkg.add("IJulia")
Pkg.build("IJulia") (Optional, execute if further error occurs again.)
⬆ Notice that the backslashes have to be doubled when you type them as a Julia string. I've just assumed that the path is your Anaconda path with \bin\jupyter appended, but replace that with whatever where jupyter tells you.
After few minutes, in Julia console execute:
using IJulia
notebook()
Now, you can program Julia in your Anaconda Jupyter Notebook.
Excellent, it worked.
However, it is important to import the package first before adding it.
import Pkg; Pkg.add("IJulia")