rye icon indicating copy to clipboard operation
rye copied to clipboard

Following a failed install, Rye refuses to install new packages

Open ananis25 opened this issue 1 year ago • 4 comments

Steps to Reproduce

rye init --script repro
cd repro/
rye sync
rye add dotenv
rye add python-dotenv

Expected Result

The first package install didn't succeed which made me realize it was the wrong one. However, it leaves the project in an aborted state. Rye shouldn't be in an aborted state and the second package install should succeed.

Actual Result

(.venv) ubuntu@ip-10-0-0-6:~/repos/notebooks$ rye init --script repro
success: Initialized project in /home/ubuntu/repos/notebooks/repro
  Run `rye sync` to get started

(.venv) ubuntu@ip-10-0-0-6:~/repos/notebooks$ cd repro/

(.venv) ubuntu@ip-10-0-0-6:~/repos/notebooks/repro$ rye sync
Initializing new virtualenv in /home/ubuntu/repos/notebooks/repro/.venv
Python version: [email protected]
Generating production lockfile: /home/ubuntu/repos/notebooks/repro/requirements.lock
Generating dev lockfile: /home/ubuntu/repos/notebooks/repro/requirements-dev.lock
Installing dependencies
   Built file:///home/ubuntu/repos/notebooks/repro                                                                 Built 1 editable in 226ms
Installed 1 package in 0ms
 + repro==0.1.0 (from file:///home/ubuntu/repos/notebooks/repro)
Done!

(.venv) ubuntu@ip-10-0-0-6:~/repos/notebooks/repro$ rye add dotenv
Added dotenv>=0.0.5 as regular dependency
Reusing already existing virtualenv
Generating production lockfile: /home/ubuntu/repos/notebooks/repro/requirements.lock
error: Failed to download and build: dotenv==0.0.5
  Caused by: Failed to build: dotenv==0.0.5
  Caused by: Failed to install requirements from build-system.requires (resolve)
  Caused by: No solution found when resolving: wheel, setuptools >=40.8.0, wheel, distribute
  Caused by: Failed to download and build: distribute==0.7.3
  Caused by: Failed to build: distribute==0.7.3
  Caused by: Build backend failed to determine metadata through `prepare_metadata_for_build_wheel` with exit status: 1
--- stdout:

--- stderr:
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: invalid command 'dist_info'
---
error: could not write production lockfile for project

Caused by:
    failed to generate lockfile

(.venv) ubuntu@ip-10-0-0-6:~/repos/notebooks/repro$ rye add python-dotenv
Added python-dotenv>=1.0.1 as regular dependency
Reusing already existing virtualenv
Generating production lockfile: /home/ubuntu/repos/notebooks/repro/requirements.lock
error: Failed to download and build: dotenv==0.0.5
  Caused by: Failed to build: dotenv==0.0.5
  Caused by: Failed to install requirements from build-system.requires (resolve)
  Caused by: No solution found when resolving: wheel, setuptools >=40.8.0, wheel, distribute
  Caused by: Failed to download and build: distribute==0.7.3
  Caused by: Failed to build: distribute==0.7.3
  Caused by: Build backend failed to determine metadata through `prepare_metadata_for_build_wheel` with exit status: 1
--- stdout:

--- stderr:
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: invalid command 'dist_info'
---
error: could not write production lockfile for project

Caused by:
    failed to generate lockfile

Version Info

rye 0.29.0
commit: 0.29.0 (42b179f36 2024-03-11)
platform: linux (x86_64)
self-python: [email protected]
symlink support: true
uv enabled: true

Stacktrace

No response

ananis25 avatar Mar 20 '24 06:03 ananis25

I agree. Unfortunately it's quite easy to mess up here. Concurrent access to the venv also messes stuff up. One way in which we could go about this is to write a state file into the .venv (eg: .venv/rye.state) during operations.

  • If it contains the pid and the pid is alive an operation is in progress ("wait for rye to finish")
  • If it's empty the last operation failed (recreate venv?)
  • If it's missing the venv is in a good state

mitsuhiko avatar Mar 22 '24 10:03 mitsuhiko

Didn't reproduce successfully on my computer (rye 0.31.0 platform: macos (aarch64)):

➜  test rye init --script repro
success: Initialized project in /Users/zhezhezhu/projects/test/repro
  Run `rye sync` to get started
➜  test cd repro/
➜  repro git:(main) ✗ rye sync
Initializing new virtualenv in /Users/zhezhezhu/projects/test/repro/.venv
Python version: [email protected]
Generating production lockfile: /Users/zhezhezhu/projects/test/repro/requirements.lock
Generating dev lockfile: /Users/zhezhezhu/projects/test/repro/requirements-dev.lock
Installing dependencies
   Built file:///Users/zhezhezhu/projects/test/repro                                                                                                                              Built 1 editable in 173ms
Installed 1 package in 0.94ms
 + repro==0.1.0 (from file:///Users/zhezhezhu/projects/test/repro)
Done!
➜  repro git:(main) ✗ rye add dotenv
error: Failed to run uv compile error: Failed to download and build: dotenv==0.0.5
  Caused by: Failed to build: dotenv==0.0.5
  Caused by: Failed to install requirements from build-system.requires (resolve)
  Caused by: No solution found when resolving: setuptools >=40.8.0, wheel, distribute
  Caused by: Failed to download and build: distribute==0.7.3
  Caused by: Failed to build: distribute==0.7.3
  Caused by: Build backend failed to determine metadata through `prepare_metadata_for_build_wheel` with exit status: 1
--- stdout:

--- stderr:
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: invalid command 'dist_info'
---
. uv exited with status: exit status: 2
➜  repro git:(main) ✗ rye add python-dotenv
Added python-dotenv>=1.0.1 as regular dependency
Reusing already existing virtualenv
Generating production lockfile: /Users/zhezhezhu/projects/test/repro/requirements.lock
Generating dev lockfile: /Users/zhezhezhu/projects/test/repro/requirements-dev.lock
Installing dependencies
   Built file:///Users/zhezhezhu/projects/test/repro                                                                                                                              Built 1 editable in 175ms
Uninstalled 1 package in 0.69ms
Installed 2 packages in 1ms
 + python-dotenv==1.0.1
 - repro==0.1.0 (from file:///Users/zhezhezhu/projects/test/repro)
 + repro==0.1.0 (from file:///Users/zhezhezhu/projects/test/repro)
Done!

ischaojie avatar Mar 22 '24 13:03 ischaojie

@ischaojie - thanks for the repro attempt! I updated Rye to 0.31 (from 0.29) and don't see the error on Linux now either.

Earlier, rye add dotenv (dotenv is the package that fails to install) was leaving behind the dotenv entry in the pyproject-toml file, which caused the failure on future sync attempts. But the add command script suggests pyproject.toml is updated only after uv has tried to resolve the dependency, so not sure what went wrong earlier.

ananis25 avatar Mar 23 '24 04:03 ananis25

removing dotenv and python-dotenv, and re-adding python-dotenv worked for me (TLDR; remove the faulty package)

devayani-14 avatar Sep 04 '24 11:09 devayani-14

removing dotenv and python-dotenv, and re-adding python-dotenv worked for me (TLDR; remove the faulty package)

Hi! How do I remove the faulty package? When I try rye remove <package_name> it still says "error: could not write production lockfile for project"

Many thanks

waychel-world avatar Oct 12 '24 09:10 waychel-world

I had to manually edit the pyproject toml.

Though, uv has come along a lot further now, maybe more useful to replace rye with it.

ananis25 avatar Oct 12 '24 09:10 ananis25