Yeah. We probably could add an item to the quick panel to let user select which conda python he wants to use for the current ST window. But that would be a manual process, plus an indicator for the name of the current activated venv is probably needed.
Recognising conda environments in lsp-pyright with latest lsp v2
maegul
#22
Thinking of maybe putting together a little plugin, at least for myself … is there any lsp/pyright API I can use to set the pythonPath without using the settings or project-settings?
0 Likes
maegul
#24
All good … thankjs so much for the help.
For anyone wondering after all that what’s the easiest way to get lsp-pyright to work with conda environments (and venv
isn’t working for you as I describe above.
- Use
pythonPath
in the project settings (see below for an eg). - If you aren’t really using the projects feature for the relevant work, then consider it as a necessary lsp-pyright config setup:
- From the menu: Project > Save Project As > insert name > save
- Open the new file ending in
.sublime-project
and add settings as provided below (you will need to know where your conda envs are located on your disk)
Eg project settings with pythonPath
provided:
{
"settings": {
"LSP": {
"LSP-pyright": {
"settings": {
"python.pythonPath": "/Users/username/miniconda3/envs/my_env/bin/python"
}
}
}
},
"folders":
[
{
"path": "."
}
]
}
I’ve got two snippets for helping with this (they could be combined into one if you prefer):
For inserting most of the boiler plate
<snippet>
<content><![CDATA[
"settings": {
"LSP": {
"LSP-pyright": {
"settings": {
"python.pythonPath": "$1"
}
}
}
},
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>pythonpath</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.json.sublime.project</scope>
</snippet>
For adding the path to the python binary, where you have to provide the name of the environment
<snippet>
<content><![CDATA[
/Users/username/miniconda3/envs/$1/bin/python
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>conda_env</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.json.sublime.project</scope>
</snippet>
0 Likes
jfcherng
#25
I think you can already do it in project settings.
{
"folders":
[
// ...
],
"settings": {
"LSP": {
"LSP-pyright": {
"settings": {
"python.pythonPath": "python" // your conda python executable
}
}
}
}
}
0 Likes