buzl.uk

Python virtual environments in Zed

21 August 2024

I've been using Zed as my main editor for over a month now. The reason I switched from VSCode was that VSCode was too slow when I was working with multiple windows open. Switching back and forth between windows was creating a lag that was unbearable. I saw Zed as a lightweight and crazy fast alternative, and I wanted to give it a try. There were some problems however...

Python

Working with virtual environments right out of the box was not possible. Because Zed uses Microsoft's Pyright language server, we have to add configurations for it based on its documentation. Usually, I name the virtual environment directory as env. So, keep that in mind when you're changing the settings for yourself. Here's what I did add in my settings.json file:

"lsp": {
    "pyright": {
        "settings": {
            "python": {
                "pythonPath": "env/bin/python",
                "venvPath": "."
            }
        }
    }
}

Both pythonPath and venvPath were necessary in my case.

Extra configurations

Besides setting options in the language server, we can directly add some extra configuration to Pyright using a pyrightconfig.json file in the root directory of your project. Here's an example of what I'm using:

{
    "reportUnusedImport": true,
    "reportUnusedClass": true,
    "reportUnusedFunction": true,
    "reportUnusedVariable": true
}

I am using these settings to get warnings for unused things in my code. It's a good way to keep your code small and clean. If you're curious about other settings I'm using, check out my dotfiles for Zed. Thanks for reading!

  1. Nine Men's Morris

    14 hours ago

  2. Building Desktop Apps with Python

    2 years ago

  3. Want extra keys? Use your earbuds

    2 years ago

  4. That time Reddit banned me for developing an app

    2 years ago

  5. How I work with Jekyll

    2 years ago

  6. Using Webmentions with GitHub Actions

    2 years ago

  7. Python virtual environments in Zed

    2 years ago

  8. Some Progressive Rock Albums You Should Listen

    2 years ago

  9. Some Places on Google Maps

    2 years ago

  10. Migrating My Website

    2 years ago

  11. Analytics With Duckdb

    2 years ago