# Use R and Python together

This article provides procedures for running R in a Python notebook and running Python in an R notebook.

Procedure: Run Python in an R Notebook with Reticulate

1. Open the ![Environment](https://resources.jetbrains.com.cn/help/img/datalore/2026.3/environment.svg)Environment tool from the left-hand sidebar. You may need to start the machine to enable the environment management interface in this tool.

2. Use the search bar on the Explore tab to find Reticulate.

![Finding Reticulate](https://resources.jetbrains.com.cn/help/img/datalore/2026.3/reticulate.png)

3. Click reticulate in the search results and click the Install button.

![Installing Reticulate](https://resources.jetbrains.com.cn/help/img/datalore/2026.3/install_package.png)

4. Confirm your action in the confirmation dialog and wait until the package is installed.

5. Restart the kernel after the package is installed.

Now, you can use Python in your R notebook. For example, you can create a pandas array as shown in the steps below.

1.
```
library(reticulate)
   py_install(packages = c("pandas"))
```

2.
```
pd <- import("pandas")
```

3.
```
pd$array(c(1, 2, 3))
```

Procedure: Run R in a Python notebook

1. Open the ![Environment](https://resources.jetbrains.com.cn/help/img/datalore/2026.3/environment.svg)Environment tool from the left-hand sidebar. You may need to start the machine to enable the environment management interface in this tool.

![Environment tool](https://resources.jetbrains.com.cn/help/img/datalore/2026.3/environment_tool.png)

2. Click Edit init.sh to install additional dependencies. This will open the `init.sh` file in the file viewer on the right side of the editor.

3. In the `init.sh` file, add the following lines:

```BASH
bash
sudo apt-get update && \
	DEBIAN_FRONTEND=noninteractive sudo apt-get install -y -q \
	#### !!!! not sure about r-essentials
	--no-install-recommends r-essentials && \
	Rscript -e "install.packages(c('ggplot2'), type = 'source')" && \
	rm -rf /var/lib/apt/lists/* && \
	apt-get clean

pip install rpy2==3.5.1
```

> **Note:**
> Make sure you use specifically the rpy2 version as the later ones are not supported for this.

