Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'NoneType' object has no attribute 'glfwGetCurrentContext'

I'm trying a tutorial on Reinforcement learning wherein I'm currently trying to use gymnasium, mujoco, to train agents. I've installed mujoco and when I try to run the program, the sim window opens for a second and throws this error. Idk what I'm doing wrong.

import gymnasium as gym
import stable_baselines3
import imageio



env=gym.make('Humanoid-v4', render_mode='human')
obs=env.reset()
env.render()
print(obs)

BTW, I'm getting the output of print(obs) which returns a tensor. It's just the sim environment which is throwing this error.

Error Traceback

Traceback (most recent call last):
  File "C:\Users\krish\anaconda3\envs\learn\lib\site-packages\gymnasium\envs\mujoco\mujoco_rendering.py", line 337, in __del__
  File "C:\Users\krish\anaconda3\envs\learn\lib\site-packages\gymnasium\envs\mujoco\mujoco_rendering.py", line 330, in free
  File "C:\Users\krish\anaconda3\envs\learn\lib\site-packages\glfw\__init__.py", line 2358, in get_current_context
AttributeError: 'NoneType' object has no attribute 'glfwGetCurrentContext'
like image 972
Vaikruta Avatar asked Oct 23 '25 14:10

Vaikruta


1 Answers

I encountered a similar issue when I was trying to use Walker2d-v4. The error message I received was:

AttributeError: 'NoneType' object has no attribute 'get_current_context'

This led me to believe that the issue might be a compatibility problem between gymnasium and the version of mujoco you are using. In my case, downgrading the mujoco package resolved the problem. It seems that gymnasium might not be fully compatible with mujoco-3.0.0 yet.

Here's what you can do to potentially resolve the issue:

  1. install proper version of mujoco package:

    pip install mujoco==2.3.7
    
  2. Download the corresponding version of mujoco:

    You can find the release here.

  1. Extract the downloaded package:

    Place it in a directory such as /home/[user-name]/.mujoco.

  2. Set the necessary environment variables:

    export LD_LIBRARY_PATH=/home/[your-user-name]/.mujoco/mujoco2.3.7/bin:/usr/lib/nvidia
    export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libGLEW.so
    

    Make sure to replace [your-user-name] with your actual username.

like image 199
Mohammad Mahdi Setak Avatar answered Oct 26 '25 03:10

Mohammad Mahdi Setak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!