1# REPL
2
3## Getting started
4
5Bring the power of [Jupyter kernels](https://docs.jupyter.org/en/latest/projects/kernels.html) to your editor! The built-in REPL for Zed allows you to run code interactively in your editor similarly to a notebook with your own text files.
6
7<figure style="overflow: hidden; border-top-left-radius: 2px; border-top-right-radius: 2px;">
8 <video loop controls playsinline>
9 <source
10 src="https://customer-snccc0j9v3kfzkif.cloudflarestream.com/aec66e79f23d6d1a0bee5e388a3f17cc/downloads/default.mp4"
11 type='video/webm; codecs="vp8.0, vorbis"'
12 />
13 <source
14 src="https://customer-snccc0j9v3kfzkif.cloudflarestream.com/aec66e79f23d6d1a0bee5e388a3f17cc/downloads/default.mp4"
15 type='video/mp4; codecs="avc1.4D401E, mp4a.40.2"'
16 />
17 <source
18 src="https://zed.dev/img/post/repl/typescript-deno-kernel-markdown.png"
19 type="image/png"
20 />
21 </video>
22</figure>
23
24## Installation
25
26Zed supports running code in multiple languages. To get started, you need to install a kernel for the language you want to use.
27
28**Currently supported languages:**
29
30- [Python (ipykernel)](#python)
31- [TypeScript (Deno)](#typescript-deno)
32
33Once installed, you can start using the REPL in the respective language files, or other places those languages are supported, such as Markdown. If you recently added the kernels, run the `repl: refresh kernelspecs` command to make them available in the editor.
34
35## Using the REPL
36
37To start the REPL, open a file with the language you want to use and use the `repl: run` command (defaults to `ctrl-shift-enter` on macOS) to run a block, selection, or line. You can also click on the REPL icon in the toolbar.
38
39The `repl: run` command will be executed on your selection(s), and the result will be displayed below the selection.
40
41Outputs can be cleared with the `repl: clear outputs` command, or from the REPL menu in the toolbar.
42
43### Cell mode
44
45Zed supports [notebooks as scripts](https://jupytext.readthedocs.io/en/latest/formats-scripts.html) using the `# %%` cell separator in Python and `// %%` in TypeScript. This allows you to write code in a single file and run it as if it were a notebook, cell by cell.
46
47The `repl: run` command will run each block of code between the `# %%` markers as a separate cell.
48
49```python
50# %% Cell 1
51import time
52import numpy as np
53
54# %% Cell 2
55import matplotlib.pyplot as plt
56import matplotlib.pyplot as plt
57from matplotlib import style
58style.use('ggplot')
59```
60
61## Language specific instructions
62
63### Python {#python}
64
65#### Global environment
66
67<div class="warning">
68
69On MacOS, your system Python will _not_ work. Either set up [pyenv](https://github.com/pyenv/pyenv?tab=readme-ov-file#installation) or use a virtual environment.
70
71</div>
72
73To setup your current python to have an available kernel, run:
74
75```
76pip install ipykernel
77python -m ipykernel install --user
78```
79
80#### Conda Environment
81
82```
83source activate myenv
84conda install ipykernel
85python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
86```
87
88#### Virtualenv with pip
89
90```
91source activate myenv
92pip install ipykernel
93python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
94```
95
96### Typescript: Deno {#typescript-deno}
97
98[Install Deno](https://docs.deno.com/runtime/manual/getting_started/installation/) and then install the Deno jupyter kernel:
99
100```
101deno jupyter --install
102```
103
104### Other languages
105
106The following languages and kernels are also supported. You can help us out by expanding their installation instructions and configuration:
107
108- [Julia (IJulia)](https://github.com/JuliaLang/IJulia.jl)
109- R
110 - [Ark Kernel](https://github.com/posit-dev/ark) - via Positron, formerly RStudio
111 - [Xeus-R](https://github.com/jupyter-xeus/xeus-r)
112- [Scala (almond)](https://almond.sh/docs/quick-start-install)
113
114## Changing which kernel is used per language {#changing-kernels}
115
116Zed automatically detects the available kernels on your system. If you need to configure a different default kernel for a
117language, you can assign a kernel for any supported language in your `settings.json`.
118
119```json
120{
121 "jupyter": {
122 "kernel_selections": {
123 "python": "conda-env",
124 "typescript": "deno",
125 "javascript": "deno"
126 }
127 }
128}
129```
130
131## Debugging Kernelspecs
132
133Available kernels are shown via the `repl: sessions` command. To refresh the kernels you can run, use the `repl: refresh kernelspecs` command.
134
135If you have `jupyter` installed, you can run `jupyter kernelspec list` to see the available kernels.
136
137```
138$ jupyter kernelspec list
139Available kernels:
140 ark /Users/z/Library/Jupyter/kernels/ark
141 conda-base /Users/z/Library/Jupyter/kernels/conda-base
142 deno /Users/z/Library/Jupyter/kernels/deno
143 python-chatlab-dev /Users/z/Library/Jupyter/kernels/python-chatlab-dev
144 python3 /Users/z/Library/Jupyter/kernels/python3
145 ruby /Users/z/Library/Jupyter/kernels/ruby
146 rust /Users/z/Library/Jupyter/kernels/rust
147```
148
149Note: Zed makes best effort usage of `sys.prefix` and `CONDA_PREFIX` to find kernels in Python environments. If you want explicitly control run `python -m ipykernel install --user --name myenv --display-name "Python (myenv)"` to install the kernel directly while in the environment.