Skip to content

Commit c816d58

Browse files
authored
Make dm_control an extra dependency (#828)
Because dm_control needs to be installed from vcs or tarball, garage cannot be directly installed in pipenv (see [this issue](pypa/pipenv#3396)). I've copied the example that used our dm_control wrapper, modified the original example to use gym, and modified the copy to clarify the extra dependency. I've also modified the `garage.env.dm_control` module to report a helpful error message if dm_control isn't found. `pip install garage[all]` will still install dm_control.
1 parent 2a80517 commit c816d58

File tree

4 files changed

+40
-7
lines changed

4 files changed

+40
-7
lines changed

examples/step_dm_control_env.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python3
2+
"""Example of how to load, step, and visualize an environment.
3+
4+
This example requires that garage[dm_control] be installed.
5+
"""
6+
from garage.envs.dm_control import DmControlEnv
7+
8+
# Construct the environment
9+
env = DmControlEnv.from_suite('walker', 'run')
10+
11+
# Reset the environment and launch the viewer
12+
env.reset()
13+
env.render()
14+
15+
# Step randomly until interrupted
16+
try:
17+
print('Press Ctrl-C to stop...')
18+
while True:
19+
env.step(env.action_space.sample())
20+
env.render()
21+
except KeyboardInterrupt:
22+
print('Exiting...')
23+
env.close()

examples/step_env.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env python3
22
"""Example of how to load, step, and visualize an environment."""
3-
from garage.envs.dm_control import DmControlEnv
3+
import gym
44

55
# Construct the environment
6-
env = DmControlEnv.from_suite('walker', 'run')
6+
env = gym.make('MountainCar-v0')
77

88
# Reset the environment and launch the viewer
99
env.reset()

setup.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@
2121
'click',
2222
'cloudpickle',
2323
'cma==1.1.06',
24-
# dm_control throws an error during install about not being able to
25-
# find a build dependency (absl-py). Later pip executes the `install`
26-
# command again and the install succeeds because absl-py has been
27-
# installed. This is stupid, but harmless.
28-
'dm_control @ https://api.github.com/repos/deepmind/dm_control/tarball/7a36377879c57777e5d5b4da5aae2cd2a29b607a', # noqa: E501
2924
'dowel==0.0.2',
3025
'gym[all]==0.12.4',
3126
'joblib<0.13,>=0.12',
@@ -50,6 +45,15 @@
5045

5146
# Dependencies for optional features
5247
extras = {}
48+
49+
extras['dm_control'] = [
50+
# dm_control throws an error during install about not being able to
51+
# find a build dependency (absl-py). Later pip executes the `install`
52+
# command again and the install succeeds because absl-py has been
53+
# installed. This is stupid, but harmless.
54+
'dm_control @ https://api.github.com/repos/deepmind/dm_control/tarball/7a36377879c57777e5d5b4da5aae2cd2a29b607a', # noqa: E501
55+
]
56+
5357
extras['all'] = list(set(sum(extras.values(), [])))
5458

5559
# dependencies for using gpu, not included in all

src/garage/envs/dm_control/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
44
See https://github.com/deepmind/dm_control
55
"""
6+
try:
7+
import dm_control # noqa: F401
8+
except ImportError:
9+
raise ImportError("To use garage's dm_control wrappers, please install "
10+
'garage[dm_control].')
11+
612
from garage.envs.dm_control.dm_control_viewer import DmControlViewer
713
from garage.envs.dm_control.dm_control_env import DmControlEnv # noqa: I100
814

0 commit comments

Comments
 (0)