-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option to select python environments #7646
Comments
I had the same questions initially. You can follow these docs to get pyright to point at your venv correctly. https://github.com/zed-industries/zed/blob/main/docs/src/languages/python.md |
@mchieco cheers, this works great! |
Not to my knowledge. It’s not actually the IDE doing the work here, it’s the LSP, and since the venv can be different per repo, i have my config stored on each. but i’m sure you could set a global config if your venv is the same on each |
Can I use conda env? I made a conda configuration as follows, but it does not work. {
"venvPath": "/Users/lxy/opt/miniconda3/envs",
"venv": "/Users/lxy/opt/miniconda3/envs/ml"
} |
sorry, that's correct, it worked. |
Can i know how yours work? Cause mine is not working. |
Specify your conda environment path as above in the |
Could you make it work with Poetry? Tried the same approach by linking the poetry env directory in pyrightconfig.json but still didn't work. |
I have put this in |
For me the full paths didn't work either what does work is the following. I have my conda envs in the folder {
"venv": "great_project",
"venvPath": "/Users/daniel/mambaforge/envs"
} |
Related #8541 |
FWIW, I made Conda (Miniforge) work on Zed and used my {
"venvPath": "/Users/daniel/miniforge3/",
"venv": "/Users/daniel/miniforge3/",
"executionEnvironments": [
{
"python": "/Users/daniel/miniforge3/bin/python"
}
]
} |
Following {
"venvPath": "/Users/allen.he/Library/Caches/pypoetry/virtualenvs/",
"venv": "cyberbiz-data-api-edPw3-qJ-py3.8"
} You can get the path via |
What if you want to use the currently active conda environment without continuously editing a configuration file? |
I use pipenv ,and the fllowing config works well {
"venvPath": "/Users/shaojiasong/.local/share/virtualenvs/",
"venv": "pandas_test-6SWXZJHk"
} notice that ,you should use full path , don't replace home path with '~' |
Is there a solution for not hard-coding the |
Is it possible to use an environment variable like $CONDA_PREFIX ?
This does not work for me :( |
Look like not working for monorepo for pyproject.toml.
|
Doesn't work for mono repo. :( |
Anyone get Zed working with |
Okay, for anyone wondering how to get {
"venv" : "pyfintech",
"venvPath" : "/Users/adrianrosebrock/.pyenv/versions"
} Additionally, take a look at pyenv-pyright which can help you generate your |
@newtome8888 Hi, i use this and it works for me 😔 Try this: {
"venvPath": "/Users/liudong/Library/Caches/pypoetry/virtualenvs",
"venv": "/Users/liudong/Library/Caches/pypoetry/virtualenvs/webserver-P4NjN8WG-py3.12"
} |
i have this in my bash profile if [[ -f "pyproject.toml" ]]; then
env_path=$(poetry env info -p)
venv_dir=$(basename "$env_path")
venv_path=$(dirname "$env_path")
if ! grep -q "\[tool.pyright\]" pyproject.toml; then
echo "[tool.pyright]" >> pyproject.toml
echo "venvPath = \"$venv_path\"" >> pyproject.toml
echo "venv = \"$venv_dir\"" >> pyproject.toml
else
if ! grep -q "venvPath" pyproject.toml; then
sed -i "/\[tool.pyright\]/a venvPath = \"$venv_path\"" pyproject.toml
fi
if ! grep -q "venv" pyproject.toml; then
sed -i "/\[tool.pyright\]/a venv = \"$venv_dir\"" pyproject.toml
fi
fi
poetry shell && clear
fi it sets [tool.pyright] in
|
tweaking this to work with other venv managers should be easy. hope it helps others solve the problem until we get it in zed. also it would be helpful if someone can direct me to where this can be implemented into zed. i can give it some time later. |
Any ideas for those using conda as prefer env manager? I am having a similar issues too. |
The idea user-work-flow for me would be to |
And if I switch conda env for example with |
I have created a simple task in the editor that allows me choose from all the virtual envs in python that I have. Upon execution it searches for all the venvs and using fzf lets me select one then creates the pyrighconfig.json in the current directory. {
"label": "(Python) : Select Virtual Env",
"env": {
"cwd": "$ZED_DIRNAME"
}
"command": "~/selectenv.sh",
"use_new_terminal": true
} where selectenv.sh is #!/bin/bash
search_venvs() {
local search_path=$1
if [ -d "$search_path" ]; then
find "$search_path" -type d -name 'bin' -exec test -e '{}/activate' \; -print 2>/dev/null | sed 's|/bin||'
fi
}
paths=(
"$PWD"
"$HOME/.local/share/virtualenvs"
"$HOME/Library/Caches/pypoetry/virtualenvs"
"$HOME/.local/share/pdm/venvs"
"$HOME/.pyenv/versions"
"$HOME/.virtualenvs"
"$HOME/.conda/envs"
)
if [ -n "$CONDA_PREFIX" ]; then
paths+=("$CONDA_PREFIX")
fi
venv_paths=()
for path in "${paths[@]}"; do
while IFS= read -r line; do
venv_paths+=("$line")
done < <(search_venvs "$path")
done
if [ ${#venv_paths[@]} -gt 0 ]; then
selected_venv=$(printf '%s\n' "${venv_paths[@]}" | fzf --prompt="Select a virtual environment: ")
if [ -n "$selected_venv" ]; then
echo "You selected: $selected_venv"
venv_name=$(basename "$selected_venv")
venv_path=$(dirname "$selected_venv")
cat <<EOL > pyrightconfig.json
{
"venvPath": "$venv_path",
"venv": "$venv_name"
}
EOL
if [ -f "pyrightconfig.json" ]; then
echo "pyrightconfig.json updated with the selected environment."
else
echo "pyrightconfig.json created with the selected environment."
fi
else
echo "No virtual environment selected."
fi
else
echo "No virtual environments found."
fi |
Run any Jupyter kernel in Zed on any buffer (editor): <img width="1074" alt="image" src="https://github.com/zed-industries/zed/assets/836375/eac8ed69-d02b-4d46-b379-6186d8f59470"> ## TODO ### Lifecycle * [x] Launch kernels on demand * [x] Wait for kernel to be started * [x] Request Kernel info on start * [x] Show in progress indicator * [ ] Allow picking kernel (it defaults to first matching language name) * [ ] Menu for interrupting and shutting down the kernel * [ ] Drop running kernels once editor is dropped ### Media Outputs * [x] Render text and tracebacks with ANSI color handling * [x] Render markdown as text * [x] Render PNG and JPEG images using an explicit height based on line-height * ~~Render SVG~~ -- not happening for this PR due to lack of text in SVG support * [ ] Process `update_display_data` message and related `display_id` * [x] Process `page` data from payloads as outputs * [ ] Render markdown as, well, rendered markdown -- Note: unsure if we can get line heights here ### Document * [x] Select code and run * [x] Run current line * [x] Clear previous overlapping runs * [ ] Support running markdown code blocks * [ ] Action to export session as notebook or output files * [ ] Action to clear all outputs * [ ] Delete outputs when lines are deleted ## Other missing features The following is a list of missing functionality or expectations that are out of scope for this PR. ### Python Environments Detecting python environments should probably be done in a separate PR in tandem with how they're used with LSP. Users likely want to pick an environment for their project, whether a virtualenv, conda env, pyenv, poetry backed virtualenv, or the system. Related issues: * #7646 * #7808 * #7296 ### LSP Integration * Submit `complete_request` messages for completions to interleave interactive variables with LSP * LSP for IPython semantics (`%%timeit`, `!ls`, `get_ipython`, etc.) ## Future release notes - Run code in any editor, whether it's a script or a markdown document Release Notes: - N/A
Run any Jupyter kernel in Zed on any buffer (editor): <img width="1074" alt="image" src="https://github.com/zed-industries/zed/assets/836375/eac8ed69-d02b-4d46-b379-6186d8f59470"> ## TODO ### Lifecycle * [x] Launch kernels on demand * [x] Wait for kernel to be started * [x] Request Kernel info on start * [x] Show in progress indicator * [ ] Allow picking kernel (it defaults to first matching language name) * [ ] Menu for interrupting and shutting down the kernel * [ ] Drop running kernels once editor is dropped ### Media Outputs * [x] Render text and tracebacks with ANSI color handling * [x] Render markdown as text * [x] Render PNG and JPEG images using an explicit height based on line-height * ~~Render SVG~~ -- not happening for this PR due to lack of text in SVG support * [ ] Process `update_display_data` message and related `display_id` * [x] Process `page` data from payloads as outputs * [ ] Render markdown as, well, rendered markdown -- Note: unsure if we can get line heights here ### Document * [x] Select code and run * [x] Run current line * [x] Clear previous overlapping runs * [ ] Support running markdown code blocks * [ ] Action to export session as notebook or output files * [ ] Action to clear all outputs * [ ] Delete outputs when lines are deleted ## Other missing features The following is a list of missing functionality or expectations that are out of scope for this PR. ### Python Environments Detecting python environments should probably be done in a separate PR in tandem with how they're used with LSP. Users likely want to pick an environment for their project, whether a virtualenv, conda env, pyenv, poetry backed virtualenv, or the system. Related issues: * zed-industries#7646 * zed-industries#7808 * zed-industries#7296 ### LSP Integration * Submit `complete_request` messages for completions to interleave interactive variables with LSP * LSP for IPython semantics (`%%timeit`, `!ls`, `get_ipython`, etc.) ## Future release notes - Run code in any editor, whether it's a script or a markdown document Release Notes: - N/A
The pixi package manager also creates conda environments and stores them in Adding something like {
"venvPath": ".pixi/envs/",
"venv": "default"
} works for pyright and IDE integration but |
in case anyone is having trouble resolving imports for a conda env even after setting the |
Check for existing issues
Describe the feature
I am only seeing option to select programming language. How can I select existing conda or venv environments in the editor ?
If applicable, add mockups / screenshots to help present your vision of the feature
No response
The text was updated successfully, but these errors were encountered: