- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
After
!pip install gymnasium stable_baselines3 Shimmy
I am getting error with import. And this does not happen in Google Colab;
import gymnasium
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[13], line 1
----> 1 import gymnasium
ModuleNotFoundError: No module named 'gymnasium'
I have tried all the kernels and no luck so far. Is there a solution for this ?
Thank you in advance. -Hakan
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi HakanBa,
Thank you for reaching out to us.
Could you kindly launch a new notebook under base kernel by clicking the New Launcher button on the top left side of JupyterLab and try to run the codes again?
I have validated on my end, and I can execute the codes using base kernel without any issue at this moment:
Do let us know if it works for you.
Regards,
Luwe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Luwe,
Thank ou for your time.
I have tried that but I get following error;
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In[2], line 1
----> 1 import gymnasium
File ~/.local/lib/python3.9/site-packages/gymnasium/__init__.py:4
1 """Root `__init__` of the gymnasium module setting the `__all__` of gymnasium modules."""
2 # isort: skip_file
----> 4 from gymnasium.core import (
5 Env,
6 Wrapper,
7 ObservationWrapper,
8 ActionWrapper,
9 RewardWrapper,
10 )
11 from gymnasium.spaces.space import Space
12 from gymnasium.envs.registration import (
13 make,
14 spec,
(...)
19 register_envs,
20 )
File ~/.local/lib/python3.9/site-packages/gymnasium/core.py:9
5 from typing import TYPE_CHECKING, Any, Generic, SupportsFloat, TypeVar
7 import numpy as np
----> 9 from gymnasium import logger, spaces
10 from gymnasium.utils import RecordConstructorArgs, seeding
13 if TYPE_CHECKING:
ImportError: cannot import name 'logger' from partially initialized module 'gymnasium' (most likely due to a circular import) (/home/ue8699a54d2b9b3ad864ce96dcfa33ae/.local/lib/python3.9/site-packages/gymnasium/__init__.py)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi HakanBa,
Could you kindly provide us your codes for further investigation of the error? For your information, the JupyterLab machines are intended for training purposes and workshops only. May I know which training are you running in Jupyter Notebook?
Regards,
Luwe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am creating a custom gymnasium enviroment. gymnasium is more formal than OpenAI gym.
And I need to be able to import gymnasium but I cannot. And I can do this with Google colab
and Jupyter Lab.
I think Intel provides jupyter notebook enviroment right ?
If import gymnasium works I will solve my problem.
As I posted in my original question I install the required packages;
!pip install gymnasium stable_baselines3 Shimmy
My code:
import gymnasium
def sorting_action_constraint_fn(action):
# Customize the constraint logic based on your requirements
i, j= action
return i != j
class GymnasiumSortingEnv(gymnasium.Env):
def __init__(self, sequence_length):
super(GymnasiumSortingEnv, self).__init__()
self.sequence_length = sequence_length
self.observation_space = gymnasium.spaces.Box(low=0, high=1, shape=(sequence_length,), dtype=np.float32)
self.action_space = gymnasium.spaces.MultiDiscrete([sequence_length, sequence_length])
self.current_sequence = np.zeros(sequence_length)
#self.reset()
def reset(self,seed=None, options=None):
self.current_sequence = np.random.rand(self.sequence_length)
#return self.current_sequence.copy()
return self.current_sequence.copy(), {}
def is_valid_action(self, action):
# Define your constraint function here
return sorting_action_constraint_fn(action)
def step(self, action):
# Validate the action
assert self.action_space.contains(action), f"Invalid action: {action}"
# Swap the elements at the specified indices
i, j = action
#if not sorting_action_constraint_fn(action):
# raise ValueError("Invalid action. Please choose a valid action.")
self.current_sequence[i], self.current_sequence[j] = self.current_sequence[j], self.current_sequence[i]
# Calculate reward
#reward = -np.sum(np.abs(np.diff(self.current_sequence))) # Negative sum of absolute differences
#reward = custom_distance_metric(self.target_sequence, self.current_sequence)
reward = 1 if np.all(np.diff(self.current_sequence) >= 0) else 0
# Check if the sequence is sorted
done = np.all(np.diff(self.current_sequence) >= 0)
# Return the new state, reward, whether the episode is done, and additional info
return self.current_sequence.copy(), reward, done, False, {}
def render(self):
print("Current Sequence:", self.current_sequence)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi HakanBa,
Thank you for the codes provided. I am able to execute them using base kernel without facing any error at this moment:
Kindly verify with us if the packages that you have installed are the same version as ours. I have attached my packages version below for your verification. You may validate it by executing the following command:
pip list
Regards,
Luwe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Luwe.
I have provided the list of packages in the attachment.
-Hakan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is it possible that my container is using different type of image than yours ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think I solved the problem.
print(sys.path)
['/opt/intel/oneapi/ospray_studio/1.0/lib',
'/opt/intel/oneapi/advisor/2024.1/pythonapi',
'/opt/intel/oneapi/intelpython/lib/python39.zip',
'/opt/intel/oneapi/intelpython/lib/python3.9',
'/opt/intel/oneapi/intelpython/lib/python3.9/lib-dynload',
'',
'/home/<myuserid>/.local/lib/python3.9/site-packages',
'/opt/intel/oneapi/intelpython/lib/python3.9/site-packages']
I have cleaned the folders under /home/<myuserid>/.local/lib/python3.9/site-packages
And installed the packages again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi HakanBa,
Could you execute the following codes to redownload and reinstall the package:
!pip install --force-reinstall --no-cache-dir gymnasium stable_baselines3 Shimmy
Do let us know if it resolves the error.
Regards,
Luwe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi HakanBa,
This thread will no longer be monitored since this issue has been resolved. If you need any additional information from Intel, please submit a new question.
Regards,
Luwe
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page