Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
aaelony committed Dec 13, 2024
0 parents commit db182e3
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "notebook_hello"
version = "0.1.0"
edition = "2021"

[dependencies]

4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@


start_notebook:
uv run --with jupyter jupyter lab
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

# Jupyter Notebook with a Rust, R, and python kernel

Steps to get it working:

1. Install `uv`. See https://docs.astral.sh/uv/getting-started/installation/

2. Start a new project:

```
uv init notebook_hello
cd notebook_hello
```

3. Add the python kernel you prefer, e.g. version 3.13

```
uv add --dev ipykernel
uv run ipython kernel install --user --name notebook_hello
uv run --python 3.13 --with jupyter jupyter lab
```

4. Set up the R kernel

- Install `R`. See https://www.r-project.org/
- Set up the R kernel

```
Rscript -e "install.packages('IRkernel'); IRkernel::installspec(); "
```

5. Set up the Rust kernel

- Install Rust. See https://www.rust-lang.org/tools/install

```
cargo install jupyter
cargo install evcxr_jupyter
```

6. Run the notebook server

```
uv run --with jupyter jupyter lab
```






You should see a notebook with the option to switch between Rust, Python, and R kernels.
121 changes: 121 additions & 0 deletions notebook-hello-with-different-kernels.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "7efbb7d8-071f-404f-8924-2bbacb9cdee6",
"metadata": {},
"source": [
"# Jupyter Notebook with a Rust, R, and python kernel\n",
"\n",
"Steps to get it working:\n",
"\n",
" - install `uv`. See https://docs.astral.sh/uv/getting-started/installation/\n",
" - install `R`. See https://www.r-project.org/\n",
" - install Rust. See https://www.rust-lang.org/tools/install\n",
"\n",
"```\n",
"uv init notebook_hello\n",
"cd notebook_hello\n",
"uv add --dev ipykernel\n",
"uv run ipython kernel install --user --name notebook_hello\n",
"uv run --with jupyter jupyter lab \n",
"```\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "82a05c78-c286-4282-88fc-5326be727f15",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello, Rustaceans!!\n",
"Rust compiler version: rustc 1.83.0 (90b35a623 2024-11-26)\n"
]
}
],
"source": [
"// NB: Manually, switch to Rust kernel first\n",
"use std::process::Command;\n",
"let output = Command::new(\"rustc\")\n",
" .arg(\"--version\")\n",
" .output()\n",
" .expect(\"Failed to get Rust version\");\n",
"let rust_version = String::from_utf8_lossy(&output.stdout).to_string();\n",
"println!(\"Hello, Rustaceans!!\");\n",
"println!(\"Rust compiler version: {}\", rust_version.trim());\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "e2b37822-dc3d-4a34-ad03-659903f98315",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello, R users!\n",
" R version 4.4.2 (2024-10-31)"
]
}
],
"source": [
"## NB: Manually switch to the R kernel first\n",
"cat(\"Hello, R users!\\n\", R.version$version.string)\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "ea2d5308-7839-43a6-a80b-3ff12c7e6bf0",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello, Python users!\n",
"Python 3.11.4\n"
]
}
],
"source": [
"print(f\"Hello, Python users!\")\n",
"!python --version"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d9cfdfa6-5948-43ea-866e-d8c8f85ecca8",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Rust",
"language": "rust",
"name": "rust"
},
"language_info": {
"codemirror_mode": "rust",
"file_extension": ".rs",
"mimetype": "text/rust",
"name": "Rust",
"pygment_lexer": "rust",
"version": ""
}
},
"nbformat": 4,
"nbformat_minor": 5
}
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

0 comments on commit db182e3

Please sign in to comment.