Improve Python detection on windows to support virtualenv activated

Open
#12,053 6 comments 2 reactions 1 assignee View on GitHub

@cderv is already working on this.

Since Feb 10, 2025.

Assessment

This issue has not been assessed yet.

Description

enhancement python-setup quarto-check windows

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
https://github.com/quarto-dev/quarto-cli/blob/ca0587692627150b5693113a89b6ce745b95b0c6/src/command/check/check.ts#L335-L337

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

Dominant language
JavaScript
Stars
6k
Forks
458
Avg merge
1d 9h
Merged PRs (30d)
41

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from quarto-dev/quarto-cli

All issues in quarto-dev/quarto-cli

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.