Windows: Use the Python Launcher to Select Python Version
danyeaw opened this issue · 4 comments
In macOS and Linux, pipx allows you to set the Python version using the --python
option. For example, pipx install --python python3.11 black
. However, in Windows, all Python executables are named python.exe
. So the only solution I have found to tell pipx the interpreter is by giving the full path like:
pipx install --python 'C:\\Users\\dan\\AppData\\Local\\Programs\\Python\\Python311\\python.exe' black
The standard way to select a Python version in Windows is with the Python Launcher. For example, py -3.11
, will launch Python 3.11. It is possible to use the launcher with pipx with pipx install --python py black
. However, I don't see a way to tell py
which version of Python to use.
How would this feature be useful?
In Windows on GitHub Actions, pipx is installed by default with Python 3.9. I would like to run the setup-python action and then tell pipx to use this later Python version.
Describe the solution you'd like
pipx install --python 3.11 black
would use py -3.11
on Windows and python3.11
in Linux/macOS. An alternative might be --python py311
which is the format tox uses.
Describe alternatives you've considered
Reinstall pipx for each Python version, or use the full path to the Python executable.
I would be glad to help implement this if there is agreement that this would be a nice enhancement.
Instead of magically mapping X.Y
to pythonX.Y
, I would prefer to make this fail without the launcher. Otherwise this seems reasonable. Contributions are welcomed.
Thanks @uranusjr for the feedback.
I was thinking that it might be nice to have common commands across platforms so that pipx would figure out the right interpreter command, but I understand wanting to avoid magical mapping.
Do you have a preference between --python 3.11
and --python py311
?
Personally I feel 3.10
reads better.
I started working on this today. I think the order of looking up python should be:
--python
is specified and then we usepy
with the version passed. Potentially should set thePY_PYTHON
environmental variable rather than trying to pass apy -3.11
command around.- Use the venv Python if in a venv
- Use py
- Use system Python
2-4 are already part of the DEFAULT_PYTHON determination. For 1, we can override the interpreter in the main
module, and put the tests and logic with the interpreter
module.
It took me a little while to figure out the workflow, all tests were failing with nox on Windows, and I submitted #1000 to fix it. Also being able to use nox -s tests-3.11 -- -k test_interpreter
which was in the contributing docs is important since the test suite takes so long to run.