'AttributeError: module 'gym.envs.box2d' has no attribute 'CarRacing' / box 2d doesn't install successfully

environment_name = 'CarRacing-v0'
env = gym.make(environment_name)

AttributeError: module 'gym.envs.box2d' has no attribute 'CarRacing'

and i did pip install box2d in anaconda prompt but it gives me some error and i cannot install box2d

error: command 'C:\Users\User\anaconda3\Library\mingw-w64\bin\gcc.exe' failed with exit code 1 ---------------------------------------- ERROR: Failed building wheel for box2d

and also i did other tries in anaconda prompt

conda create -c conda-forge -n gymenv swig pip 
conda activate gymenv
pip install Box2D gym

but still this error comes out

AttributeError: module 'gym.envs.box2d' has no attribute 'CarRacing'

how can i solve this error...? and i also added swig in environment variables

enter image description here



Solution 1:[1]

I think the problem is the pyglet package is not installed,
so it cannot run.

try to do:
pip install pyglet

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 finko