zed icon indicating copy to clipboard operation
zed copied to clipboard

editor fails to pick python .venv correctly or accept the path when entered.

Open bkgthumanity opened this issue 6 months ago • 15 comments

Summary

editor fails to pick python .venv correctly or accept the path when entered.

Description

Steps to reproduce:

  1. have a python project one folder level down in a project eg /main_project_folder/python_project 2.venv stored in /main_project_folder/python_project/.venv (venv is failed to be picked up automatically.
  2. Then click on venv folder in footer of editor and pasting in the full path location . zed returns 'No matches'
  3. venv isn't picked up... imports all broken

Expected Behavior: venv picked up automatically and or can be set manually with full path Actual Behavior: both fail.

specifying it in settings.json also doesn't help. and specifying the venv in a pyproject.toml also doesn't help (or trying only one of these options).

setting extract

"languages": {
    "Python": {
      "show_edit_predictions": false,
      "language_servers": ["pyright", "ruff"],
      "project_root": "agent",
      "format_on_save": "on",
      "python_path": "/Users/yunti/Dev/traffease_man/agent/.venv/bin/python",
      "formatter": [
        {
          "language_server": {
            "name": "ruff"
          }
        },
        {
          "code_actions": {
            "source.organizeImports.ruff": true,
            "source.fixAll.ruff": true

Zed Version and System Specs

Zed: v0.185.10 (Zed) OS: macOS 15.3.2 Memory: 16 GiB Architecture: aarch64

Image

bkgthumanity avatar May 07 '25 15:05 bkgthumanity

Thanks for reporting. Seems to be a duplicate of #27331.

Also note that neither "project_root" nor "python_path" are valid keys in language specific settings, we should show an error message for this but unfortunately our language settings validation isn't great right now.

probably-neb avatar May 07 '25 16:05 probably-neb

@probably-neb I'm not sure it's a duplicated issue. Things were working well since a recent update (less than one week ago).

Image

Now, the editor cannot find non native python package.

CedricRaison avatar May 07 '25 16:05 CedricRaison

@probably-neb I'm not sure it's a duplicated issue. Things were working well since a recent update (less than one week ago).

Image

Now, the editor cannot find non native python package.

Yes it was working better before. A pyproject.toml seemed to help but without this the venv wasn't picked up, but now it's doesn't work at all (as of the last week or two).

bkgthumanity avatar May 07 '25 16:05 bkgthumanity

Understood, reopening

probably-neb avatar May 07 '25 20:05 probably-neb

Understood, reopening

Thanks should I reword the title to make it clearer and distinct from the other issue?

bkgthumanity avatar May 08 '25 06:05 bkgthumanity

Zed updated to 0.185.12 today and all imports from installed packages in a virtualenv stopped working.

The virtualenv name is recognised and shown at the bottom right though. I'm not sure if this is the same bug?

Image

My complete settings:

{
  "ui_font_size": 20,
  "buffer_font_size": 23.0,
  "theme": {
    "mode": "system",
    "light": "Zed Legacy: Atelier Sulphurpool Dark",
    "dark": "One Dark"
  },
  "languages": {
    "Python": {
      "language_servers": ["!pylsp", "pyright"]
    }
  }
}

Zed 0.185.12 Ubuntu 24.10

afandian avatar May 08 '25 13:05 afandian

Zed updated to 0.185.12 today and all imports from installed packages in a virtualenv stopped working.

The virtualenv name is recognised and shown at the bottom right though. I'm not sure if this is the same bug?

Image

My complete settings:

{
  "ui_font_size": 20,
  "buffer_font_size": 23.0,
  "theme": {
    "mode": "system",
    "light": "Zed Legacy: Atelier Sulphurpool Dark",
    "dark": "One Dark"
  },
  "languages": {
    "Python": {
      "language_servers": ["!pylsp", "pyright"]
    }
  }
}

Zed 0.185.12 Ubuntu 24.10

@afandian thanks! actually when using the downloaded pylsp from Zed, the completion/suggestion from lsp looks extremely slow. After applying you configuration, Lsp completion works like a charm. IMHO, I think with the default lsp setup, there are some race conditions happened between Zed edit suggestion versus lsp completion on key stroke. Thank you once again.

greatMonster11 avatar May 09 '25 10:05 greatMonster11

@greatMonster11 I think this is entirely separate to this specific issue but glad it was useful! The workaround is from here: https://github.com/zed-industries/zed/issues/21076#issuecomment-2508893051

afandian avatar May 09 '25 12:05 afandian

This is really a terrible issue. I wish it will be fixed as soon as possible, or otherwise I could only downgrade Zed version :(

Hammerklavier-cn avatar May 10 '25 18:05 Hammerklavier-cn

This is really a terrible issue. I wish it will be fixed as soon as possible, or otherwise I could only downgrade Zed version :(

Have you tried adding this to pyproject.toml?

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

volfpeter avatar May 12 '25 08:05 volfpeter

I think this can be reproduced without the nested project structure:

  • Clone this repo: https://github.com/volfpeter/fasthx
  • Run poetry install (make sure you have the venv in project folder setting set in some way)
  • Open the repo in Zed -> virtual env and installed libs are both correctly recognized
  • Open pyproject.toml
  • Remove the [tool.pyright] section from the config and save the file -> virtual env is still seemingly recognized, but installed libs are not

Here's my settings file:

{
  "edit_predictions": {
    "mode": "eager",
    "copilot": {
      "proxy": null,
      "proxy_no_verify": null
    },
    "enabled_in_text_threads": false
  },
  "buffer_font_size": 13,
  "ui_font_size": 16,
  "unnecessary_code_fade": 0.8,
  "features": {
    "edit_prediction_provider": "zed"
  },
  "agent": {
    "default_model": {
      "provider": "google",
      "model": "gemini-2.0-flash"
    },
    "version": "2"
  },
  "languages": {
    "Python": {
      "format_on_save": "on",
      "formatter": [
        {
          "code_actions": {
            "source.organizeImports.ruff": true,
            "source.fixAll.ruff": true
          }
        },
        {
          "language_server": {
            "name": "ruff"
          }
        }
      ]
    }
  },
  "project_panel": {
    "auto_reveal_entries": false
  },
  "tabs": {
    "git_status": true
  },
  "telemetry": {
    "metrics": true
  },
  "theme": {
    "mode": "system",
    "light": "One Light",
    "dark": "Github Dark"
  }
}

volfpeter avatar May 12 '25 08:05 volfpeter

This is really a terrible issue. I wish it will be fixed as soon as possible, or otherwise I could only downgrade Zed version :(

Have you tried adding this to pyproject.toml?

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

This fixes the linter errors but the original bug still remains that Zed doesn't recognize the virtual environments that start with a period. i.e. .venv when using uv.

sarmadgulzar avatar May 12 '25 17:05 sarmadgulzar

This is really a terrible issue. I wish it will be fixed as soon as possible, or otherwise I could only downgrade Zed version :(

Have you tried adding this to pyproject.toml?

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

Nope. But I don't know why zed picks up .venv environment correctly all of a sudden. Both pylsp and pyright works fine on v0.186.6-pre.

Hammerklavier-cn avatar May 13 '25 16:05 Hammerklavier-cn

Still facing the issue. Tried all workarounds. no luck. - Zed 0.188.5

vrvlive avatar Jun 01 '25 12:06 vrvlive

I am about to re-land the changes that were reverted at the end of April in https://github.com/zed-industries/zed/pull/31893; this means that soon the venv situation should be a bit better.

osiewicz avatar Jun 02 '25 13:06 osiewicz

I use the ruff in my venv, and while pyright and testing seem to be fixed, ruff is still broken. Not sure if this is related but pyright also doesn't pick up the settings in pyproject.toml at the root of the repo, and I don't know how to point it at it explicitly.

superlopuh avatar Jun 12 '25 11:06 superlopuh

@bkgthumanity Are you still seeing this?

notpeter avatar Jun 20 '25 19:06 notpeter

@bkgthumanity Are you still seeing this?

Nope all fixed now thanks.

bkgthumanity avatar Jun 21 '25 11:06 bkgthumanity