pytorch / rl

A modular, primitive-first, python-first PyTorch library for Reinforcement Learning.
https://pytorch.org/rl
MIT License
2.37k stars 314 forks source link

[BUG] Unable to install torchrl via pip #2035

Closed laurenzlevi closed 4 months ago

laurenzlevi commented 8 months ago

Describe the bug

Unable to install torchrl via pip for python312.

>>> pip install torchrl
ERROR: Could not find a version that satisfies the requirement torchrl (from versions: none)
ERROR: No matching distribution found for torchrl

To Reproduce

Fresh install of python 3.12, running pip install torchrl triggers the error mentioned above.

Installing via pip install git+https://github.com/pytorch/rl.git gives the error message

ERROR: Could not find a version that satisfies the requirement tensordict>=0.4.0 (from torchrl) (from versions: 0.0.1a0, 0.0.1b0, 0.0.1rc0, 0.0.2a0, 0.0.2b0, 0.0.3, 0.1.0, 0.1.1, 0.1.2)
ERROR: No matching distribution found for tensordict>=0.4.0

Installing tensordict via pip install git+https://github.com/pytorch-labs/tensordict works and allows for a subsequent installation of torchrl via pip install git+https://github.com/pytorch/rl.git, but using the module leads to the following error

Traceback (most recent call last):
  File "C:\Projects\repos\Rainbow-DQN\test.py", line 1, in <module>
    from torchrl.modules.models import NoisyLazyLinear
  File "C:\Users\pixel\AppData\Local\Programs\Python\Python312\Lib\site-packages\torchrl\__init__.py", line 10, in <module>
    from tensordict import set_lazy_legacy
  File "C:\Users\pixel\AppData\Local\Programs\Python\Python312\Lib\site-packages\tensordict\__init__.py", line 6, in <module>
    from tensordict._lazy import LazyStackedTensorDict
  File "C:\Users\pixel\AppData\Local\Programs\Python\Python312\Lib\site-packages\tensordict\_lazy.py", line 24, in <module>
    from functorch import dim as ftdim
  File "C:\Users\pixel\AppData\Local\Programs\Python\Python312\Lib\site-packages\functorch\dim\__init__.py", line 7, in <module>
    import functorch._C
ImportError: initialization failed

Expected behavior

torchrl should install.

System info

Describe the characteristic of your environment:

System information:

Checklist

vmoens commented 8 months ago

We don't support 3.12 atm but that will be the case for the next major release I think!

laurenzlevi commented 8 months ago

Ah okay I´ll be using 3.11 then for now, is there any approximate release window for the next major version and should I close the issue or leave it open for others to see?

wbinventor commented 7 months ago

I am also curious if there are any (approximate) plans for a new major (or even minor) release?

vmoens commented 7 months ago

I'm behind schedule for the 0.3.2 minor because the CI was giving me some issues and I couldn't guarantee that the wheels were working fine. I will try to release it shortly!

0.4 will be there soon (PyTorch release day is tomorrow, expect the v0.4 release in the days after)

GaetanLepage commented 6 months ago

For me, tensordict 0.4.0 is still broken for python 3.12 as it relies on the now deprecated distutils package:

RuntimeError: First class dim doesn't work with python 3.12

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/nix/store/v9avkh4lq80zm23sjrr5jfk0f06xhgpx-python3.12-tensordict-0.4.0/lib/python3.12/site-packages/tensordict/_lazy.py", line 26, in <module>
    from functorch import dim as ftdim
  File "/nix/store/pn0xqrvfqf7cri031497b7y3nprfjyx7-python3.12-torch-2.2.2/lib/python3.12/site-packages/functorch/dim/__init__.py", line 7, in <module>
    import functorch._C
ImportError: initialization failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 1, in <lambda>
  File "/nix/store/aav6i2sih47qjwz0shpl4mmpp877v16k-python3-3.12.3/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/nix/store/v9avkh4lq80zm23sjrr5jfk0f06xhgpx-python3.12-tensordict-0.4.0/lib/python3.12/site-packages/tensordict/__init__.py", line 6, in <module>
    from tensordict._lazy import LazyStackedTensorDict
  File "/nix/store/v9avkh4lq80zm23sjrr5jfk0f06xhgpx-python3.12-tensordict-0.4.0/lib/python3.12/site-packages/tensordict/_lazy.py", line 30, in <module>
    from tensordict.utils import _ftdim_mock as ftdim
  File "/nix/store/v9avkh4lq80zm23sjrr5jfk0f06xhgpx-python3.12-tensordict-0.4.0/lib/python3.12/site-packages/tensordict/utils.py", line 22, in <module>
    from distutils.util import strtobool
ModuleNotFoundError: No module named 'distutils'
vmoens commented 6 months ago

Same 3.12 issue I'm afraid! I will work on making a release for 3.12 for 0.4.1, but no promises! Please bear with me on this one!

GaetanLepage commented 6 months ago

Sure no worry. I just wanted to ensure that you knew it was still broken.

Best of luck with that :)

chnyutao commented 6 months ago

Related issue here. I see that since v0.4.0 all macOS x86 builds are removed and I have to build wheels from source. May I ask why macOS x86 is no longer supported? Thanks :)

vmoens commented 6 months ago

This saddens me too very much, but the latest pytorch release (2.3) doesn't support x86 anymore so there was no way for us to release v0.4 for these platforms :( https://github.com/pytorch/pytorch/releases/tag/v2.2.0 So sorry about that! This one's way beyond my control

chnyutao commented 6 months ago

No worries. One more reason to update my old laptop ;)

carschandler commented 3 weeks ago

Hey there, I wanted to chime back in on this issue because I'm failing to import with the same distutils error message on Python 3.12 / torchrl 0.6.0 on linux_x86-64.

EDIT: after digging into this a bit more, it seems that somehow my environment (using pixi as my package manager) had gotten borked and a pixi clean followed by pixi install was enough to get import distutils working again (provided through setuptools)