Skip to content

Improve Python detection on windows to support virtualenv activated #12053

@cderv

Description

@cderv

Currently on Windows, Quarto detection relies on

  • QUARTO_PYTHON being set
  • The py.exe launcher being available (with optionally PY_PYTHON being set)
  • conda being used

However, in situation where pyenv is used to manage python install, or even uv nowadays, it creates problem. All the more because virtual env is not even taken into account at this step of detection

caps = await jupyterCapabilities();
});
if (caps) {

cd $env:TEMP
mkdir quarto
cd quarto

uv has some python installed

❯ uv python find
C:\Users\chris\AppData\Roaming\uv\python\cpython-3.13.1-windows-x86_64-none\python.exe

Let's initialize a project with Python 3.13.1

uv init --python 3.13.1
uv add jupyter

Now the version of python for the project is the one from the venv

❯ uv python find
C:\Users\chris\AppData\Local\Temp\quarto\.venv\Scripts\python.exe

But Quarto find none

❯ uv run quarto check jupyter
Quarto 1.7.13
[>] Checking Python 3 installation....(None)

      Unable to locate an installed version of Python 3.
      Install Python 3 from https://www.python.org/downloads/

Activating virtualenv puts the python binary on PATH

❯ .\.venv\Scripts\activate
❯ (gcm python).Source
C:\Users\chris\AppData\Local\Temp\quarto\.venv/Scripts\python.exe

But still quarto can't find it

❯ quarto check jupyter
Quarto 99.9.9
[>] Checking Python 3 installation....(None)

      Unable to locate an installed version of Python 3.
      Install Python 3 from https://www.python.org/downloads/

This is because

  • VIRTUAL_ENV env var is not check at detection step but later for kernel spec information
  • windows has python.exe on PATH and not python3.exe and dectection code does not account for that.

If py.exe was available then it would work.

❯ cd C:\Users\chris\AppData\Local\Temp\quarto
❯ py -0
No installed Pythons found!
❯ .\.venv\Scripts\activate
❯ py -0
  *               Active venv
❯ quarto check jupyter
Quarto 99.9.9
[>] Checking Python 3 installation....OK
      Version: 3.13.1
      Path: C:/Users/chris/AppData/Local/Temp/quarto/.venv/Scripts/python.exe
      Jupyter: 5.7.2
      Kernels: python3, julia-1.11

[>] Checking Jupyter engine render....OK

So current situation on windows does rely too much on py.exe which is only available for user using Windows Store Python version, or installing from the Python official website.

Related to

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestpython-setupIssues with Python's environment and setupquarto-checkRelated to `quarto check`windows

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions