#1701·Gymnasium

[Bug Report] `gymnasium[torch]` and `gymnasium[jax]` install conversion wrappers that fail to import: `No module named 'packaging'`

Author: caiotheodoroCreated Sep 12, 2026Updated Sep 14, 2026

Describe the bug

pip install "gymnasium[torch]" into a fresh environment, followed by from gymnasium.wrappers import NumpyToTorch, raises ModuleNotFoundError: No module named 'packaging'. pip install "gymnasium[jax]" followed by from gymnasium.wrappers import JaxToNumpy raises the same error. Neither extra depends on packaging, but gymnasium/wrappers/array_conversion.py:29 imports packaging.version.Version at module level, and every conversion wrapper imports that module. #1437 added packaging to the array-api extra only.

The try/except ImportError at array_conversion.py:35-41, which is meant to turn a missing dependency into DependencyNotInstalled with a pip hint, cannot run: from array_api_compat import is_numpy_namespace (line 28) and from packaging.version import Version (line 29) sit above it. So a base install with no extras gets a bare ModuleNotFoundError: No module named 'array_api_compat' from gymnasium.wrappers.ArrayConversion, and tests/wrappers/test_import_wrappers.py::test_all_wrappers_shortened fails for ArrayConversion, JaxToNumpy, JaxToTorch and NumpyToTorch instead of skipping on DependencyNotInstalled as it does for the other optional wrappers.

The vector JaxToNumpy, JaxToTorch and NumpyToTorch wrappers have the same shape: import jax.numpy as jnp and import torch are unguarded at the top of each module. That also makes the if jnp is None: check in gymnasium/wrappers/vector/jax_to_numpy.py:34 unreachable.

Code example

bash
uv venv --python 3.11 venv && source venv/bin/activate
uv pip install "gymnasium[torch]==1.3.0"
uv pip list | grep -i packaging   # nothing
python -c "from gymnasium.wrappers import NumpyToTorch"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File ".../site-packages/gymnasium/wrappers/__init__.py", line 184, in __getattr__
    module = importlib.import_module(import_stmt)
  File ".../lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File ".../site-packages/gymnasium/wrappers/numpy_to_torch.py", line 11, in <module>
    from gymnasium.wrappers.array_conversion import (
  File ".../site-packages/gymnasium/wrappers/array_conversion.py", line 29, in <module>
    from packaging.version import Version
ModuleNotFoundError: No module named 'packaging'

Base install, no extras:

bash
uv pip install ./Gymnasium   # main at ec4715d, no extras
python -c "import gymnasium; gymnasium.wrappers.ArrayConversion"
  File ".../gymnasium/wrappers/array_conversion.py", line 28, in <module>
    from array_api_compat import is_numpy_namespace
ModuleNotFoundError: No module named 'array_api_compat'

System info

Reproduced in four fresh uv venv --python 3.11 environments on macOS arm64, Python 3.11.15, numpy 2.4.6:

  • PyPI gymnasium[torch]==1.3.0: torch 2.14.0, array-api-compat 1.15.0, no packaging. Traceback above.
  • main at ec4715d, uv pip install "./Gymnasium[torch]": same packages, same failure, array_conversion.py line 29.
  • main at ec4715d, uv pip install "./Gymnasium[jax]": jax 0.10.2, jaxlib 0.10.2, flax 0.12.8, array-api-compat 1.15.0, no packaging. from gymnasium.wrappers import JaxToNumpy fails with the same No module named 'packaging'.
  • main at ec4715d, uv pip install ./Gymnasium with no extras: ArrayConversion raises ModuleNotFoundError: No module named 'array_api_compat' instead of DependencyNotInstalled.

CI does not see either failure. bin/all-py.Dockerfile installs .[all,testing], and bin/necessary-py.Dockerfile installs .[testing], whose pytest depends on packaging and whose array_api_extra depends on array-api-compat.

Additional context

Two changes fix it, and they are independent of each other:

  1. Add packaging >=23.0 to the torch and jax extras in pyproject.toml, matching what #1437 did for array-api.
  2. Move the two module-level imports in array_conversion.py inside the existing try block, and guard import jax.numpy / import torch in the three vector wrappers the same way the single-env jax_to_numpy.py, jax_to_torch.py and numpy_to_torch.py already do.

I have a PR ready with both plus a regression test that blocks each module via sys.modules in a subprocess and asserts on DependencyNotInstalled.

hit this while working on a project of mine.

Checklist

  • I have checked that there is no similar issue in the repo

Source: Farama-Foundation/Gymnasium