astral-sh / rye

a Hassle-Free Python Experience
https://rye.astral.sh
MIT License
13.45k stars 459 forks source link

Failed to prepare distributions #1350

Open Inasayang opened 2 weeks ago

Inasayang commented 2 weeks ago

Steps to Reproduce

I uninstalled rye and reinstalled it in a different location. When I open the previous project again and run rye sync, it gives an error.

❯ rye sync       
Reusing already existing virtualenv
Generating production lockfile: C:\Users\inasa\Desktop\pyproject\requirements.lock
Generating dev lockfile: C:\Users\inasa\Desktop\pyproject\requirements-dev.lock
Installing dependencies
Resolved 14 packages in 12ms
error: Failed to prepare distributions
  Caused by: Failed to fetch wheel: pyproject @ file:///C:/Users/inasa/Desktop/pyproject
  Caused by: Failed to create temporary virtualenv
  Caused by: Could not find a suitable Python executable for the virtual environment based on the interpreter: C:\Users\inasa\.rye\py\cpython@3.11.9\python.exe
error: Installation of dependencies failed in venv at C:\Users\inasa\Desktop\pyproject\.venv. uv exited with status: exit code: 2

But rye show can output the information correctly.

❯ rye show
project: pyproject
path: C:\Users\inasa\Desktop\pyproject
venv: C:\Users\inasa\Desktop\pyproject\.venv
target python: 3.8
venv python: cpython@3.12.5
virtual: false
configured sources:
  default (index: https://pypi.org/simple/)

But there are no issues with newly created projects.

I tried to delete .venv and then run rye sync, but there was still no change.

Expected Result

❯ rye sync
Reusing already existing virtualenv
Generating production lockfile: C:\Users\inasa\Desktop\pyproject2\requirements.lock
Generating dev lockfile: C:\Users\inasa\Desktop\pyproject2\requirements-dev.lock
Installing dependencies
Resolved 1 package in 6ms
Audited 1 package in 0.37ms
Done!

Actual Result

❯ rye sync
Reusing already existing virtualenv
Generating production lockfile: C:\Users\92867\Desktop\pyproject\requirements.lock
Generating dev lockfile: C:\Users\92867\Desktop\pyproject\requirements-dev.lock
Installing dependencies
Resolved 14 packages in 13ms
error: Failed to prepare distributions                                                                                                                                 
  Caused by: Failed to fetch wheel: pyproject @ file:///C:/Users/92867/Desktop/pyproject
  Caused by: Failed to create temporary virtualenv
  Caused by: Could not find a suitable Python executable for the virtual environment based on the interpreter: C:\Users\92867\.rye\py\cpython@3.11.9\python.exe        
error: Installation of dependencies failed in venv at C:\Users\92867\Desktop\pyproject\.venv. uv exited with status: exit code: 2

Version Info

❯ rye --version
rye 0.39.0
commit: 0.39.0 (bf3ccf818 2024-08-21)
platform: windows (x86_64)
self-python: cpython@3.12.5
symlink support: false
uv enabled: true

Stacktrace

No response

lorenzogatti commented 2 weeks ago

Where is "cpython@3.11.9", which evidently doesn't exist any more after uninstalling Rye, referenced in the files of your project? Do you want to download cpython@3.11.9 as a "toolchain" or upgrade the project to the already available cpython@3.12.5 of the new Rye installation?

Inasayang commented 2 weeks ago

upgrade the project to the already available cpython@3.12.5 of the new Rye installation. How to do this?

bluss commented 2 weeks ago

I would try the following:

rye pin 3.12
rye sync -f

Using -f on sync will delete the old .venv instead of trying to use it, so it needs to reinstall everything.

Inasayang commented 2 weeks ago

When I execute rye sync -f, the following error occurs:

❯ rye sync -f 
error: failed to delete existing virtualenv (at 'C:\Users\inasa\Desktop\pyproject\.venv')

Caused by:
    Access is denied. (os error 5)

Running the cmd with administrator privileges also results in the same error.

But when I manually delete the .venv and then execute rye sync -f, it works.

Inasayang commented 2 weeks ago

When I open it again, it doesn't work.

pyproject on  main [?] is 📦 v0.1.0 via 🐍 v3.12.5 (pyproject) 
❯ rye pin 3.12
pinned 3.12.5 in C:\Users\inasa\Desktop\pyproject\.python-version

pyproject on  main [?] is 📦 v0.1.0 via 🐍 v3.12.5 (pyproject) 
❯ rye sync -f 
Initializing new virtualenv in C:\Users\inasa\Desktop\pyproject\.venv
Python version: cpython@3.12.5
Generating production lockfile: C:\Users\inasa\Desktop\pyproject\requirements.lock
Generating dev lockfile: C:\Users\inasa\Desktop\pyproject\requirements-dev.lock
Installing dependencies
Resolved 14 packages in 13ms
error: Failed to prepare distributions
  Caused by: Failed to fetch wheel: pyproject @ file:///C:/Users/inasa/Desktop/pyproject
  Caused by: Failed to create temporary virtualenv
  Caused by: Could not find a suitable Python executable for the virtual environment based on the interpreter: C:\Users\inasa\.rye\py\cpython@3.11.9\python.exe
error: Installation of dependencies failed in venv at C:\Users\inasa\Desktop\pyproject\.venv. uv exited with status: exit code: 2
bluss commented 2 weeks ago

Do you have any .python-version or .python-versions files in this directory or any above? Look everywhere :)

Inasayang commented 2 weeks ago

image

lumina37 commented 2 weeks ago

I also met the same issue, here's the log

  Caused by: Failed to create temporary virtualenv
  Caused by: Could not find a suitable Python executable for the virtual environment based on the interpreter: C:\Users\Administrator\.rye\py\cpython@3.12.3\python.exe

the temporary solution is rye fetch 3.12.3. I wonder why my rye requires 3.12.3 to operate everything?

Inasayang commented 1 week ago

the environment variables

RYE_HOME=D:\rye\bin
RYE_TOOLCHAIN=D:\rye\toolchain

Always look in the C:\Users\inasa\.rye directory.