I am trying to get my environment setup to train a deep Q network with TF-Agents. However, I'm getting a bunch of import errors that I can't seem to resolve. The tutorial I am following, here, required the following packages:
tf-agents[reverb]
pyvirtualdisplay
imageio==2.4.0
pyglet
And then the had the following big import statement:
from __future__ import absolute_import, division, print_function
import base64
import imageio
import IPython
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import PIL.Image
import pyvirtualdisplay
import reverb
import tensorflow as tf
from tf_agents.agents.dqn import dqn_agent
from tf_agents.drivers import py_driver
from tf_agents.environments import suite_gym
from tf_agents.environments import tf_py_environment
from tf_agents.eval import metric_utils
from tf_agents.metrics import tf_metrics
from tf_agents.networks import sequential
from tf_agents.policies import py_tf_eager_policy
from tf_agents.policies import random_tf_policy
from tf_agents.replay_buffers import reverb_replay_buffer
from tf_agents.replay_buffers import reverb_utils
from tf_agents.trajectories import trajectory
from tf_agents.specs import tensor_spec
from tf_agents.utils import common
I'm working in a virtual environment with python 3.9.6 on a Windows OS. After installing the packages above (with pip install) and running the above code, I was missing these modules (ModuleNotFound
): matplotlib, reverb, and tensorflow. I ran another pip install for matplotlib, which fixed that issue. However, reverb and tensorflow were not straightforward. I ran a separate pip install for reverb (pip install reverb
), but now the I get the following error on import reverb
:
Cell In [3], line 11
import reverb
File c:\...\env\lib\site-packages\reverb.py:64
raise TypeError, 'Regexp cannot be negated'
^
SyntaxError: invalid syntax
Similarly, when I ran a separate pip install tensorflow
, I was met with:
WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.tracking.base has been moved to tensorflow.python.trackable.base. The old module will be deleted in version 2.11.
(traceback)
ImportError: cannot import name 'network' from 'tensorflow.python.keras.engine' (c:\...\env\lib\site-packages\tensorflow\python\keras\engine\__init__.py)
I'm guessing that this import error is because tf-agents installed its own versions of tensorflow in ./env/, but I don't understand why python couldn't import them. Does anyone have any advice as to how to resolve these dependency issues so I can just run the notebook? Are there imports I should just omit, or do a different way? Is the problem with my pip install? Any advice is appreciated.