In this blog, I will set up a virtual environment using pip, It is always better to make a virtual environment in order to perform some machine learning or reinforcement learning or any other task which depends upon different library version. You can also create a virtual environment using Anaconda but in this blog, I will go with the virtual environment created using pip. The rest of the steps will be the same.
The first thing you have to do is to install the package that will be used to create the virtual environment
pip install virtualenv
Next is to create a virtual environment using pip with the following command:
virtualenv striker source ./striker/bin/activate
Now the virtual environment is activated. Next, install important libraries to run the retro.
pip install tensorflow pip install retro
Next run the Airstriker-Genesis game with the sample actions.
import retro
def main():
env = retro.make(game='Airstriker-Genesis')
obs = env.reset()
while True:
obs, rew, done, info = env.step(env.action_space.sample())
env.render()
if done:
obs = env.reset()
env.close()
if __name__ == "__main__":
main()
When you run this code you will get this error.
Traceback (most recent call last):
File "airstriker.py", line 71, in <module>
env = retro.make(game_name)
AttributeError: module 'retro' has no attribute 'make'
To solve this error just uninstall the retro and install the gym-retro package you will ready to go.
pip uninstall retro pip install gym-retro
This worked for me, If it doesn’t work then delete the virtual environment create another environment and install the gym-retro package first.
Now when you run the above code you will get dependency conflicts, you will get this output:
Installing collected packages: cloudpickle, pyglet, gym, gym-retro
ERROR: After October 2020 you may experience errors when installing or updating packages. This is because pip will change the way that it resolves dependency conflicts.
We recommend you use --use-feature=2020-resolver to test your packages with the new resolver before it becomes the default.
gym 0.17.2 requires pyglet<=1.5.0,>=1.4.0, but you'll have pyglet 1.5.7 which is incompatible.
In order to solve this issue install the pyglet==1.5.0 using the following command:
pip install pyglet==1.5.0
Now you are ready to go to run the Airstriker-Genesis.
That’s it for now but In the next blog, I will run Airstriker-Genesis game using DQN.