OpenAI Gym mujoco-py wheel compilation error during installation

I’m having trouble installing the complete OpenAI Gym package. When I try to install it with all dependencies, I get a wheel building error for mujoco-py. The basic gym installation works fine and I can import both gym and mujoco_py successfully, but the full installation fails.

Here’s what I’m running:

(myenv) user@computer:~/gymnasium$ pip install -e .'[all]'

The installation starts collecting packages and seems to work for most dependencies, but fails when it tries to build mujoco-py. I can see it’s trying to build the wheel and then hits this syntax error in the builder.py file. The error shows something about invalid syntax around a print statement.

I’m using Python 2.7 in an anaconda environment. All the other packages like scipy, numpy, requests, and pyglet install without issues. The error specifically mentions a SyntaxError in the mujoco_py builder module.

Can anyone help me understand what’s causing this syntax error during the wheel building process? Is this a Python version compatibility issue or something else?

yea, ur right! mujoco-py and py2.7 just don’t mix. u def need to upgrade to at least python 3.6 to get past those syntax errors. after that it should go smoother. good luck, hope it works out!

mujoco-py dropped Python 2.7 support ages ago. When pip tries building the wheel, it hits modern Python syntax that 2.7 can’t handle - print statements with parentheses, newer string operations, etc. I’ve been there with old simulation code. That builder.py syntax error you’re seeing? It’s just the first problem. Even if you patch the obvious syntax issues, the C++ bindings and dependencies all expect Python 3 features. Just migrate to Python 3.6+ in a fresh environment. Installation’s dead simple once you’re on a supported version.

That syntax error is definitely a Python 2.7 compatibility issue. I hit this exact problem about a year ago setting up an older research environment. The mujoco-py library uses Python 3 syntax that doesn’t exist in 2.7 - mainly print statements and string formatting. You’ve got two options: upgrade to Python 3.6+ or find an older mujoco-py version that still worked with 2.7. I’d strongly recommend upgrading Python though. 2.7 is dead and most packages don’t support it anymore. The conda upgrade is usually pretty straightforward and you’ll avoid these headaches going forward.

seriously, just create a new env with python 3. it’s way easier than dealing with the issues in 2.7. mujoco-py has not supported 2.7 for ages, so you’ll be wasting time on fixes that don’t really work. good luck!

I hit this same issue with legacy code. The problem is mujoco-py’s build system expects Python 3 syntax - print functions and f-strings that don’t exist in Python 2.7. Your wheel compilation is trying to run Python 3 code with a 2.7 interpreter, so you get syntax errors. Even if you patch these immediate issues, you’ll run into more problems since mujoco-py development moved entirely to Python 3. I created a fresh Python 3.7 environment just for this project and saved myself hours of debugging. The gym ecosystem works way better with modern Python versions anyway.