A quick guide to set up Zed editor for Python programming on Mac OS

Naren Yellavula
Dev bits
Published in
7 min readSep 3, 2024

--

Python + Zed = Productivity (Logo Copyright PSF & Zed industries)

Hi readers, in this article, I will show how to quickly install Zed editor, a modern Rust, and GPU-based text editor. I’ve been using it for three months for personal and professional work, and really impressed by it’s speed, low memory-footprint and minimalism over VSCode.

Let’s begin the show. The first step is to install a package manager to simplify one’s life.

A) Install Brew & Python

This section installs required components for Python programming. If you already have brew installed, skip to Step 2.

1) Install HomeBrew (required)

First you need to make sure you have HomeBrew package manager on Mac OS. You can install it easily by running the command in your Terminal/Shell:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

This will download a shell script using CURL and installs brew package manager on your MacOS device.

You can test the installation by running the brew help command to print available sub commands:

brew -h

If you see the list, you have the brew package manager installed. Moving on to the next step.

2) Install Miniconda (required)

You can install a global virtual environment manager like Conda instead of creating separate ones in each project. Conda provides many high-level environment & package management capabilities but also guarantees cross-platform compatibility. Therefore I strongly recommend using a virtual environment manager like conda or pyvenv.

For this article, we use miniconda which is a free offering from Anaconda without bells and whistes. Install miniconda on your Mac device with the following brew command:

brew install miniconda

This fetches latest stable Python interpreter version (Ex: Python 3.12_24 etc.) and creates a base environment. Once completed, you have to run another command to initialize conda whenever you launch a shell.

conda init "$(basename "${SHELL}")"

Close & Relaunch your Terminal/Shell. Now activate the base environment like this:

conda activate base

Now you have a Python interpreter readily available that is using Conda environment instead of system. To confirm that you are using miniconda’s Python environment, type the command:

which python

and it will show the linked Python interpreter like this:

/opt/homebrew/Caskroom/miniconda/base/bin/python

The above output means everything is working as expected. Otherwise, you have to run conda activate base again.

3. Install required third-party packages (optional)

After activating Conda virtual environment, to install any third-party packages from PyPi, you can run the command:

pip install package

or install packages from a file named requirements.txt

pip install -r requirements.txt

Now you have a base Python interpreter with required packages installed on base Conda environment. Let’s go ahead and install the Zed editor.

B) Install Zed editor

Zed is great for beginners as well as experienced Python programmers. Developers need fewer distractions, and zed provides peace of mind by avoiding bloated features. It comes with a default Python language server that leverages the Pyright static type checker.

1. Install Zed editor

You can easily install Zed editor using this brew package manager which we already installed in step A.1. Run this command to install it effortlessly.

brew install zed

Once installed, you will see an icon called Zed in your Mac applications list and can be launched on demand. By default, zed uses VSCode key map for editor. You can switch to Atom or

2. Open a project in Zed

To open an existing project/directory in Zed, you can run the command from shell:

zed -n directory
View of Zed editor

I opened a simple project called addnumbers in the screenshot. You can also launch a Terminal/Shell session in Zed itself, by clicking on small shell icon on right bottom task pane depicted in following screenshot. This is useful for running Python programs or other required services.

Launching shell in Zed editor (Follow the yellow arrow)

One can open zed settings by navigating from Zed next to apple icon in application menu bar (top left), and navigating to Settings -> Open Settings . This will open the file showed in the screenshots. This is the global settings which are shared by all zed editor windows. You can also change configuration only scoped to a given project by modifying local settings. It can be done by navigating to Settings -> Open Local Settings

You can also access these settings quickly by launching command palette with Command + Shift + p and searching for settings keyword.

Now, we need to setup Python interpreter for our project and configure a code linter.

3. Setup Python interpreter for a project

If you recall, I mentioned Zed uses Pyright as a static checker and we can configure pyright to pick up Python interpreter path.

Create a new file called pyproject.tomlin any project with below content in it:

[tool.pyright]
venvPath = "/opt/homebrew/Caskroom/miniconda"
venv = "base"

This configuration tells Zed editor to use virtual environment given at a specific directory (miniconda virtual environments). As you can see, when we typed which python in shell we got:

`/opt/homebrew/Caskroom/miniconda/base/bin/python`

Here, /opt/homebrew/Caskroom/miniconda is directory that has all created virtual environments and base is name of virtual environment.

If you are not using miniconda, but a virtual environment directory called venv in local directory, you can modify the pyproject.toml file to this:

[tool.pyright]
venvPath = "."
venv = "venv"

This sets up python interpreter to do import checks and symbol suggestions in code editor but only scoped for project.

Important: Restart Zed editor to apply this setting.

4. Install Ruff linter extension

Zed recommends using Ruff linter for code linting (styling). It is fast, modern and compatible with various Python style guides like PEP-8. It is a good addition to Pyright static checker. Another alternative to Ruff is pylint.

This linter is not part of vanilla editor, so must be installed separately by hitting Cmd + Shift + p and selecting zed: extensions . Now search for Ruff and install it.

3. Enable Ruff linter along with Pyright in a project by navigating to local zed settings. It can be reached by hitting Cmd + shift + p on keyboard and select zed: open local settings . This will create a new file named ./zed/settings.json with empty {} JSON configuration. Now copy following block to it and save.

{
"languages": {
"Python": {
"language_servers": ["pyright", "ruff"]
}
}
}

5. Set `autosave` settings

To automatically save a file on focus change (to new window or terminal), add autosave key in the local settings JSON.

{
"languages": {
"Python": {
"language_servers": ["pyright", "ruff"]
}
},
"autosave": "on_focus_change"
}

6. Setup local zed tasks for Python

We can setup zed tasks to run a command against a given file/directory:

- Run a main program

To create a task, hit Cmd + shift + p and select zed: open local settings

And copy this JSON content to the file .zed/tasks.json:

[
{
"label": "Run project",
"command": "/opt/homebrew/Caskroom/miniconda/base/bin/python",
"args": ["main.py"],
"use_new_terminal": false,
"shell": "system"
}
]

You can run this task by hitting Cmd + shift + p and selecting task: spawn , then selecting Run project option. It will launch a new terminal window with the result of run. This is handy to modify a project in different places but quickly re-run the program to see desired output.

Note: You can even use Flask or Django server-startup run commands in as value forargs.

7. Run unit tests in Zed

Zed comes with first-class support to run unittests written using Python unittestpackage. Let’s say we have three files in the project: main.py , operations.py and test_operations.py , Zed editor shows Play icon on the left gutter in the test file.

operations.py

def add(x: int, y: int) -> int:
if not isinstance(x , int) or not isinstance(y, int):
raise ArithmeticError()

return x + y

main.py

from operations import add

if __name__ == "__main__":
# Use imported functions
add(2, 3)

test_operations.py

import unittest
from operations import add

class TestOperations(unittest.TestCase):
def test_add_positive_integers(self):
result = add(3, 5)
self.assertEqual(result, 8)

def test_add_negative_integers(self):
result = add(-3, -5)
self.assertEqual(result, -8)

def test_add_float_should_raise_error(self):
with self.assertRaises(ArithmeticError):
add(3, 5.1)

Now you can click on Play button in test file next to class to run all tests in the test case:

Run unit tests (Follow yellow arrows)

Conclusion

Zed is a minimalistic code editor which doesn’t consume too much CPU or memory like VSCode or JetBrains PyCharm IDE. It is a breath of fresh air for Python development. Definitely try it out and I am quite sure you will make it the mainstream editor for all your projects.

There’s a local Kubernetes (k3s) cluster running in background while editing code samples for this article, and thanks to Zed editor.

Thanks for reading my article and see you again!

References:

--

--