Prefer `py` on Windows when available
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.2k
- Forks
- 1k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 66
Description
Did you know on Windows, the default installation options don't include installing Python on the PATH, but the default installation options do include installing the py launcher on the PATH? Perhaps pyo3 could be smarter and fall back to py -3 or simply py when no executable is specified.
I tried setting PYO3_PYTHON=py to see if a generic executable as found on the path could be supplied, so that I don't have to think about which Python executable to use, but that produced a different error:
Unable to create process using '"C:\Program Files\Python 3.11\py""': The system cannot find the file specified.
That error looks like it's revealing a couple of possible bugs:
- The mis-matched double-quotes suggest that maybe quotes are being added incorrectly.
- The routine seemingly inferred a Python installation at "C:\Program Files\Python 3.11", but then weirdly put $PYO3_PYTHON at the end of it, which isn't where the launcher is found. Why if the routine could find "C:\Program Files\Python 3.11" could it not find "python.exe" there?
Since the routine seemed to be able to infer the location of some Python executable, I tried setting PYO3_PYTHON=python, but that caused the Microsoft Store to launch, prompting install of Python 3.10, and pyo3 reported yet another error: error: Python script failed.
It would be nice if pyo3 could infer the location more consistently with what a user might expect on Windows, so that most users could rely on a default behavior, similar to how they can for launching Python interactively.
Originally posted by @jaraco in https://github.com/PyO3/pyo3/issues/1616#issuecomment-1305887742
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue centers on PYO3_PYTHON and Windows Python executable discovery; start by tracing how that variable is parsed and how the process command is formed. Reproduce the reported py, py -3, and quoting cases on Windows, then verify that the intended fallback works without malformed paths or quotes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- build-system, operating-systems
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100