Replies: 17 comments 25 replies
-
Hey @albas99, I'm using Zed with Python on a Poetry project with no significant issues. Here are the steps for my setup: # Create a virtual environment at the root of my project.
# Note: you may want to add the `.venv/` folder to `.gitignore`
python3 -m venv .venv
# Tell Poetry to use .venv
## Note: I use https://direnv.net/ and have the following command in my .envrc file,
## so every time I spin up a new terminal, my virtual environment is ready.
poetry env use .venv/bin/python3.11
# Configure Pyright (necessary for Zed)
## https://docs.zed.dev/languages/python
echo '{
"venvPath": ".",
"venv": ".venv"
}' > pyrightconfig.json From here on, everything should work as expected, both in Zed and in my terminals.
The one above I think it may be considered a bug, but I haven't yet found the time to write down some steps to reproduce it. 😬 I hope this helps. |
Beta Was this translation helpful? Give feedback.
-
Hi @fdionisi, thanks for the help😁, the thing is I want to use poetry's virtual environment, due to how it manages dependencies. I'm not familiar with venv(I normally use conda, and now poetry). |
Beta Was this translation helpful? Give feedback.
-
Seems like being able to launch language servers in a specific environment is a much more common need than just among Nix users. Would be nice to see some progress towards that. |
Beta Was this translation helpful? Give feedback.
This comment has been hidden.
This comment has been hidden.
-
Hey @albas99, after a bit more digging, I found an interesting solution that can work with Poetry, Pyright and Zed, similarly to what I mentioned in my original response message. By default, Poetry creates virtual environments in the cache directory (e.g. So the outcome would be: # Tell Poetry to create virtualenvs directly in the project.
poetry virtualenvs.in-project true
# Create a virtual environment at the root of my project.
# Note: you may want to add the `.venv/` folder to `.gitignore`
poetry env use 3.11
# Configure Pyright (necessary for Zed)
## https://docs.zed.dev/languages/python
echo '{
"venvPath": ".",
"venv": ".venv"
}' > pyrightconfig.json At this point, I can add Django ( Footnotes |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for the help @fdionisi , I've configured poetry to create virtualenvs in my project folder in the future, now it seems to recognized my imports, I don't know if it has something to do with the change or it finally recognized my configuration file. |
Beta Was this translation helpful? Give feedback.
-
I was making a little script for this. It does the job but I'm still tweaking it. |
Beta Was this translation helpful? Give feedback.
-
@fdionisi Did you mean to put |
Beta Was this translation helpful? Give feedback.
-
You don't need to change anything about your project settings to get pyright to find your Poetry virtualenv. All you need to do is to run $ poetry env info
Virtualenv
Python: 3.11.1
Implementation: CPython
Path: /Users/mikelane/Library/Caches/pypoetry/virtualenvs/reddit-get-40JF5hkq-py3.11
Executable: /Users/mikelane/Library/Caches/pypoetry/virtualenvs/reddit-get-40JF5hkq-py3.11/bin/python
Valid: True
System
Platform: darwin
OS: posix
Python: 3.11.1
Path: /Users/mikelane/.pyenv/versions/3.11.1
Executable: /Users/mikelane/.pyenv/versions/3.11.1/bin/python3.11 In my case, all I had to do was to add this section to my [tool.pyright]
venvPath = "/Users/mikelane/Library/Caches/pypoetry/virtualenvs"
venv = "reddit-get-40JF5hkq-py3.11" I did have to restart zed to get the squiggles to go away. I should look at the source code to see if I can add that. Or maybe is there a plugin system for zed? I'm very new to this editor, so bear with me 😆 |
Beta Was this translation helpful? Give feedback.
-
This feels like it should be converted into a Discussion. Lots of good information here. |
Beta Was this translation helpful? Give feedback.
-
Oof, missed the part where this referenced an existing Discussion ... oops. |
Beta Was this translation helpful? Give feedback.
-
Is anyone working with Conda on Zed? |
Beta Was this translation helpful? Give feedback.
-
Has anyone gotten pyright working with pyenv? I used pyenv-pyright to create the {
"venv" : "appkitgui",
"venvPath" : "/Users/user/.pyenv/versions"
} But no luck when restarting zed and of course, no helpful error messages about not finding the venv. I really want to give zed a try but it's lack of support for python is a deal breaker. I wish they could copy whatever VSCode is doing to make python environments "just work". VSCode has no problem finding the venv whether I use |
Beta Was this translation helpful? Give feedback.
-
This issue is what is keeping me from using zed. I have tried using it several times but the use of pyright as LSP (which frankly, is very lacking) and having to add a file to every single project just so pyright can find the venv makes the python experience with zed painful. VSCode has found a way to "just work" regardless of whether you're using venv, virtualenv, poetry, or pyenv. I wish zed would figure out what VSCode is doing and copy it. VSCode also allows the user to select a different venv in the editor. |
Beta Was this translation helpful? Give feedback.
-
According to the documentation, it should be enough to specify the {
"lsp": {
"pyright": {
"initialization_options": {
"python": {
"pythonPath": ".venv/bin/python"
}
}
}
}
} For those who have a single name for the virtual environment directory across all projects, it’s a pretty good solution. Yet it doesn’t work. And it doesn’t matter if I’m not a big fan of having excessive A brief and quick glance at the code yielded no clues yet. It probably deserves a separate issue, so I’ll dig further when I have attention to spare. |
Beta Was this translation helpful? Give feedback.
-
In case anybody is interested with miniforge/anaconda envs the right way to configure them is like this: {
"venv": "envname",
"venvPath": "/home/user/miniforge3/envs"
} |
Beta Was this translation helpful? Give feedback.
-
This feature has now been implemented and merged in #19576 and will hopefully be released very soon. Shout out to @osiewicz for implementing this feature. |
Beta Was this translation helpful? Give feedback.
-
Discussed in https://github.com/zed-industries/community/discussions/1037
Originally posted by albas99 March 10, 2023
I'm using Zed along with the Warp terminal app, and even though I've configured my virtual environment using Poetry, Zed is still flagging my code and doesn't seem to be recognizing the interpreter. How can I configure it so it can recognize it?
UPDATE: I've managed to configure pyright in my
pyproject.toml
file but it's still not working. I'm still gettingimport django.contrib not resolved
and I have django installed in the poetry environment.Beta Was this translation helpful? Give feedback.
All reactions