Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: Use the Python Launcher to Select Python Version #940

Closed
danyeaw opened this issue Feb 12, 2023 · 4 comments · Fixed by #1002
Closed

Windows: Use the Python Launcher to Select Python Version #940

danyeaw opened this issue Feb 12, 2023 · 4 comments · Fixed by #1002
Labels
enhancement New feature or request windows

Comments

@danyeaw
Copy link
Sponsor Contributor

danyeaw commented Feb 12, 2023

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.

@uranusjr
Copy link
Member

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.

@danyeaw
Copy link
Sponsor Contributor Author

danyeaw commented Feb 14, 2023

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?

@uranusjr
Copy link
Member

Personally I feel 3.10 reads better.

@danyeaw
Copy link
Sponsor Contributor Author

danyeaw commented Jun 11, 2023

I started working on this today. I think the order of looking up python should be:

  1. --python is specified and then we use py with the version passed. Potentially should set the PY_PYTHON environmental variable rather than trying to pass a py -3.11 command around.
  2. Use the venv Python if in a venv
  3. Use py
  4. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants