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

PIPX_DEFAULT_PYTHON not as flexible as --python #1523

Open
pitrou opened this issue Aug 29, 2024 · 5 comments
Open

PIPX_DEFAULT_PYTHON not as flexible as --python #1523

pitrou opened this issue Aug 29, 2024 · 5 comments

Comments

@pitrou
Copy link

pitrou commented Aug 29, 2024

Describe the bug

While --python allows flexible ways of specifying the desired interpreter (by version, by path...), the environment variable PIPX_DEFAULT_PYTHON only allows a full path to the Python executable.

How to reproduce

# export PIPX_DEFAULT_PYTHON=3.10
# pipx install xkcdpass
Traceback (most recent call last):
  File "/usr/local/bin/pipx", line 5, in <module>
    from pipx.main import cli
  File "/usr/local/lib/python3.8/site-packages/pipx/main.py", line 22, in <module>
    from pipx import commands, constants, paths
  File "/usr/local/lib/python3.8/site-packages/pipx/commands/__init__.py", line 2, in <module>
    from pipx.commands.environment import environment
  File "/usr/local/lib/python3.8/site-packages/pipx/commands/environment.py", line 6, in <module>
    from pipx.interpreter import DEFAULT_PYTHON
  File "/usr/local/lib/python3.8/site-packages/pipx/interpreter.py", line 183, in <module>
    DEFAULT_PYTHON = _get_absolute_python_interpreter(env_default_python)
  File "/usr/local/lib/python3.8/site-packages/pipx/interpreter.py", line 174, in _get_absolute_python_interpreter
    raise PipxError(f"Default python interpreter '{env_python}' is invalid.")
pipx.util.PipxError: Default python interpreter '3.10' is invalid.
# export PIPX_DEFAULT_PYTHON=
# pipx install --python=3.10 xkcdpass
⚠️ No executable for the provided Python version '3.10' found in PATH. Please make sure the provided version is on your PATH or the file path is valid. The
    provided version looks like a version, but both the python command and the Python Launcher were not found on PATH.

Expected behavior

# export PIPX_DEFAULT_PYTHON=3.10
# pipx install xkcdpass
⚠️ No executable for the provided Python version '3.10' found in PATH. Please make sure the provided version is on your PATH or the file path is valid. The
    provided version looks like a version, but both the python command and the Python Launcher were not found on PATH.
@uranusjr
Copy link
Member

Personally I don’t think it is a good idea to set PIPX_DEFAULT_PYTHON to anything but a full path in the first place. The meaning of 3.10 (or anything but an absolute path) can change shifts underneath, and it is too much implicity. Of course the same applies to pipx install --python, but you need to explicitly opt into the implicity, and it only applies for one command.

@mcint
Copy link

mcint commented Nov 4, 2024

Just pass the executable name or path, i.e. python3.10 or /usr/bin/python3.10, etc as appropriate for you.

Try PIPX_DEFAULT_PYTHON=python3.10 pipx install xkcdpass

Although pipx run -h does report either as usable,

--python PYTHON       Python to install with. Possible values can be the executable name (python3.11), the version to pass to py launcher
                      (3.11), or the full path to the executable.Requires Python 3.8 or above.

It looks like "python launcher", package py providing executable py (and genesis project of py.test / pytest), is in "maintenance mode", and lists most recent supported version of Python :: 3.10, per https://pypi.org/project/py/

$ pipx run --python=3.10 python3.10 -V
⚠️ No executable for the provided Python version '3.10' found in PATH. Please make sure the provided version is on your PATH or the file
    path is valid. The provided version looks like a version for Python Launcher, but `py` was not found on PATH.

https://github.com/pytest-dev/py
https://py.readthedocs.io/en/latest/

Just pass the executable name or path.

@pitrou
Copy link
Author

pitrou commented Nov 4, 2024

@mcint Did you generate your response using ChatGPT? It does not seem to make sense at all.

@mcint
Copy link

mcint commented Nov 4, 2024

I'm all ears if you want to meaningfully invite me to engage.

Sorry that adding context from my own brief poking around has proved inscrutably beneath engagement.


Am I mistaken in assuming "python launcher" that handles finding a python version when passed a version number is https://pypi.org/project/py/?

It seems that your request [support version-number-only specification] [additionally, when passed as an environment variable], is provided by a legacy library.

I would love to be corrected, and learn about better tools or other tools for managing python environment in succinct and easy ways.

@pitrou
Copy link
Author

pitrou commented Nov 4, 2024

In case someone is reading this who is not a generative IA, answer to the question posted above:

Am I mistaken in assuming "python launcher" that handles finding a python version when passed a version number is https://pypi.org/project/py/?

Yes, you are. The Python launcher for Windows (py.exe) is actually provided by the standard installers:
https://docs.python.org/3/using/windows.html#launcher

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants