positron icon indicating copy to clipboard operation
positron copied to clipboard

Using uv leads to a failed ipykernel installation

Open jthomasmock opened this issue 1 year ago • 1 comments

Positron Version: 2024.05.0 (Universal) build 1160 Code - OSS Version: 1.89.0 Commit: 5024068198dcf8f5c3560dce8e6bf8affd9580cb Date: 2024-05-08T03:21:09.376Z Electron: 28.2.8 Chromium: 120.0.6099.291 Node.js: 18.18.2 V8: 12.0.267.19-electron.0 OS: Darwin arm64 23.4.0

Steps to reproduce the issue:

  1. Install the uv tool
  2. Create a new project/folder and navigate to it.
  3. $ uv venv to create a new virtual environment.
  4. This will prompt Positron to ask you to use the .venv as the default for the workspace. Select yes which will also attempt to install ipykernel and select Yes.
  5. Because uv doesn't include pip in the .venv, the pip install ipykernel will fail as it needs to be uv pip install ipykernel instead

What did you expect to happen?

It would be nice if Positron could work with uv to install packages.

Were there any error messages in the output or Developer Tools console?

jthomasmock avatar May 10 '24 01:05 jthomasmock

Cross-posting: https://dev.to/astrojuanlu/python-packaging-is-great-now-uv-is-all-you-need-4i2d

Using:

uv init
uv add ipykernel

Creates a .venv and installs ipykernel, but Positron has a popup to prefer this .venv and tries to install ipykernel with pip directly, then throws an error.

jthomasmock avatar Aug 20 '24 00:08 jthomasmock

I think Positron should support uv in the project creation phase. If uv is detected, it should appear under this dropdown (along with venv and conda)

image

I also scratch my head trying to develop a workflow which would allow me to use Positron projects with uv-managed environments.

dmi3kno avatar Sep 26 '24 13:09 dmi3kno

In #6020 we are adding support for installing pip when it is missing (in order to install ipykernel). This is going to feel real bad to uv users, so when we add support for detecting uv environments and correctly installing into them, we should also confirm we are never installing pip into uv environments.

cc @samclark2015

juliasilge avatar Jan 18 '25 00:01 juliasilge

Note that you can use uv venv --seed to workaround this issue, because the --seed flag installs pip for you.

austin3dickey avatar Jan 21 '25 15:01 austin3dickey

I'll also note that it looks like uv encodes some metadata into the pyenv.cfg and we could sniff that to use uv pip install ipykernel but I'm not sure if all the different methods of managing Python will also add that metadata:

#! pyenv.cfg
home = /Users/thomasmock/.pyenv/versions/3.12.0/bin
implementation = CPython
uv = 0.2.37 #<<-- uv version info
version_info = 3.12.0
include-system-site-packages = false
relocatable = false
prompt = uv-testing

jthomasmock avatar Jan 22 '25 21:01 jthomasmock

I clarified the title of this issue to reflect the scope of what we're thinking about. To call this issue complete, we'd like to recognize uv-managed Python interpreters, and use uv to install packages in them. That should solve the bug in the original post and build the foundation for solving issues like https://github.com/posit-dev/positron/issues/5165 and https://github.com/posit-dev/positron/issues/6175.

austin3dickey avatar Feb 05 '25 16:02 austin3dickey

I scoped this particular issue back to the original bug. It should be solved as of https://github.com/posit-dev/positron/pull/6294, because we no longer need to install ipykernel, so we no longer try to use pip in a pip-less environment.

The additional scope I had talked about earlier became these two issues, which can be solved separately:

  • https://github.com/posit-dev/positron/issues/6476
  • https://github.com/posit-dev/positron/issues/6477

austin3dickey avatar Feb 25 '25 20:02 austin3dickey

Verified Fixed

Positron Version(s) : Main on 2/26/25
OS Version          : ubuntu

Test scenario(s)

CI now uses uv without issue

Link(s) to TestRail test cases run or created:

testlabauto avatar Feb 26 '25 22:02 testlabauto