pixi icon indicating copy to clipboard operation
pixi copied to clipboard

Support automatic recognition of pixi environments in IDEs: VS Code

Open Zaubeerer opened this issue 2 years ago • 8 comments

Problem description

As discussed on Discord, there currently isn't a proper integration with VS Code yet.

It would be great if pixi environments automagically show up when selecting the Python interpreter via Python: Select Interpreter (see VS Code Python Interpreter Docs), as do conda, poetry, venv and other environments.

Current workaround

Manually select the pixi environment python executable as described in the VS Code Docs and mentiond in https://github.com/prefix-dev/pixi/issues/166#issuecomment-1616602232.

However, this may not work for all VS Code Python features as described in #412.

Related information

  • https://code.visualstudio.com/docs/python/environments#_how-the-extension-chooses-an-environment-automatically
  • https://code.visualstudio.com/docs/python/environments#_where-the-extension-looks-for-environments

Zaubeerer avatar Oct 25 '23 16:10 Zaubeerer

I would really love that! But I really hope that it could be made without any ties to Python. I really like that Pixi positions itself as being cross-platform and ecosystem-agnostic. So many people don't see Conda as a general-purpose package manager, because they think it's Python-only. And I see where it comes from, but I hope it won't be the case for Pixi.

E.g. direnv has nice VS Code extensions that would load the environment into the IDE on startup. Probably something like that could be done for Pixi.

burdiyan avatar Dec 02 '23 19:12 burdiyan

I started some initial work here: https://github.com/microsoft/vscode-python/pull/22968

Lets see what happens!

baszalmstra avatar Feb 26 '24 14:02 baszalmstra

It seems there is a problem for jupyter notebooks inside vscode. It is possible to manually specify a pixi python interpreter as kernel but vscode does not detect ipykernel even if it is installed:

Running cells with 'envs/.pixi/envs/default/bin/python' requires the ipykernel package.
Run the following command to install 'ipykernel' into the Python environment. 

j-bac avatar Apr 02 '24 12:04 j-bac

@j-bac is ipykernel in the same environments as the python interpeter you specify here?

ruben-arts avatar Apr 02 '24 13:04 ruben-arts

Yes it is part of the pixi.toml (which defines a single environment)

[pypi-dependencies]
ipykernel = ">=6.29.3,<6.30"

j-bac avatar Apr 02 '24 14:04 j-bac

I was able to get the IPython kernel to work in VS Code by running the kernelspec install inside the pixi environment.

[tasks]
install-kernel = "python -m ipykernel install --user --name <kernel name> --display-name <kernel name>"

abkfenris avatar Apr 02 '24 14:04 abkfenris

Thanks that worked!

j-bac avatar Apr 02 '24 14:04 j-bac

A side effect of no auto-discovery is that if you initialise a new project and create a Jupyter notebook - VSCode won't show you any Pixi kernels before you firstly, create any .py file and manually select your Pixi env's Python interpreter. After a restart of the Jupyter notebook, you will be able to use that Pixi Python interpreter as a kernel without having to run any kernel creation commands manually. I assume most VSCode users will be used to this pattern by now, but thought I'd mention it incase anyone is doing that dance for the first time 😁

b4rlw avatar May 13 '24 11:05 b4rlw

I guess this issue can be closed, right? Amazing work @baszalmstra! 🥳

roaldarbol avatar Jul 02 '24 12:07 roaldarbol

Closing as it is included in the 2024.10.0 version: https://github.com/microsoft/vscode-python/releases/tag/v2024.10.0

ruben-arts avatar Jul 09 '24 17:07 ruben-arts

Question, the release notes also mention adding support for https://github.com/microsoft/python-environment-tools. This does not support Pixi: https://github.com/microsoft/python-environment-tools/issues/46. What is the difference between this and the locator? From an outsider perspective they seem to do the same.

visr avatar Jul 09 '24 19:07 visr