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

Bad error message when python query encounters python 2 #1693

Closed
fervand1 opened this issue Feb 19, 2024 · 10 comments · Fixed by #1905
Closed

Bad error message when python query encounters python 2 #1693

fervand1 opened this issue Feb 19, 2024 · 10 comments · Fixed by #1905
Assignees
Labels
bug Something isn't working error messages Messaging when something goes wrong windows Specific to the Windows platform

Comments

@fervand1
Copy link

fervand1 commented Feb 19, 2024

Steps to reproduce:

  • Install uv using command - irm https://astral.sh/uv/install.ps1 | iex

  • Run command - uv venv. You will see error shown in the screenshot
    image

  • The current uv platform - windows 10

  • uv version - 0.1.5

Note: In the windows path I only have path related to python 2. I also have python 3.10 and 3.12 installed but they can be ran using "py" command and are not added to the path. So something like py -3.10 -m venv venv creates python 3.10 env

Since 'py' command is accepted norm on windows , I would expect the tool to run with the same and not consider python 2.7 path as a default python path.
Also preferably during install it should prompt what python version he would expect to run uv from maybe?

@sbrugman
Copy link
Contributor

For Python2.7 this is to be expected, as base_prefix was introduced in 3.3 1

What does py -3.10 -m uv venv output?

@fervand1
Copy link
Author

fervand1 commented Feb 19, 2024

@sbrugman I did not install the tool for python 3.10, so currently it raises following. I installed it globally with the powershell script mentioned in the pypi docs
image

@fervand1
Copy link
Author

@sbrugman So I installed uv for python 3.10 and tried to create venv as you mentioned. The error is the same. It is taking Python 2 path into consideration.
image

@MichaReiser
Copy link
Member

Sorry you're experiencing this. I'm currently looking into improving the python discovery on Windows see #1310. I hope that this will fix your issue too.

@MichaReiser MichaReiser added the windows Specific to the Windows platform label Feb 19, 2024
@MichaReiser MichaReiser self-assigned this Feb 19, 2024
@fervand1
Copy link
Author

Thanks @MichaReiser for the quick response

@fervand1
Copy link
Author

@MichaReiser I created #1698 just as observation. It is possibly a side effect of the issue you are working on already but reported just in case it can help to improve the solution. thanks

@MichaReiser
Copy link
Member

@fervand1 can you give it a try once #1711 is released?

I suspect that this might solve your problem because it changes the precedence to first query py before searching PATH in accordance with virtualenv.

The question that remains is if we should be more lenient when it comes to failures querying the python information and instead continue searching for other "functioning" installation. @konstin what do you think?

@konstin
Copy link
Member

konstin commented Feb 22, 2024

We don't support python 2; We should check for python major != 3 and raise an error in the script we pass to python

@konstin konstin added the bug Something isn't working label Feb 22, 2024
@konstin konstin changed the title Error running uv venv command on windows 10 Bad error message when python query encounters python 2 Feb 22, 2024
@konstin konstin added the error messages Messaging when something goes wrong label Feb 22, 2024
@konstin
Copy link
Member

konstin commented Feb 22, 2024

The question that remains is if we should be more lenient when it comes to failures querying the python information and instead continue searching for other "functioning" installation. @konstin what do you think?

We should special case python 2 (e.g. returns a specific json message), but otherwise it think we should at least for now show errors. If we encounter many unrelated errors, we can be more lenient later

@fervand1
Copy link
Author

@MichaReiser I installed new version of uv via irm and it seems to be resolved.
image

Also I noticed we can pass --python param to specify which python we need. Passing 3.10 produced following
image

konstin pushed a commit that referenced this issue Feb 23, 2024
## Summary

Fixes #1693

`uv` currently fails when a user has `python` 2 or older installed on
their system without a `python3` or `python3.exe` on their path because
the `get_interpreter_info.py` script fails executing (it uses some
Python 3+ APIs).

This PR fixes this by:

* Returning an explicit error code in `get_interpreter_info` if the
Python version isn't supported
* Skipping over this error in `python_query` if the user requested ANY
python version or a version >= 3.
* Error if the user requested a Python 2 version. 

## Test Plan

Error if the user requests a legacy python version. 

```
uv venv -p 2
  × Python 2 or older is not supported. Please use Python 3 or newer.
```


Ignore any python 2 installation when querying newer python
installations (using v4 here because I have python3 on the path and that
takes precedence over querying python)
```
 uv_interpreter::python_query::find_python selector=Major(4)
      0.005541s   0ms DEBUG uv_interpreter::interpreter Detecting markers for: /home/micha/.pyenv/shims/python
      0.059730s  54ms DEBUG uv_interpreter::python_query Found a Python 2 installation that isn't supported by uv, skipping.
      0.059983s  54ms DEBUG uv_interpreter::interpreter Using cached markers for: /usr/bin/python
  × No Python 4 In `PATH`. Is Python 4 installed?

```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working error messages Messaging when something goes wrong windows Specific to the Windows platform
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants