I am creating a custom environment, but from my understanding, the problem is due to conflicts with gym/gymnasium releases. This is the context:
I am working in a Kaggle notebook
I manually tested the new environment myEnv, each function (init, reset, step) in every condition manually for instance running step with every possible actions sequence. After a while, the behavior has been stabilized and no other bugs appeared
For the new custom environment I am using Gymnasium, not Gym. And I use the name gym
# RL ENVS
import gymnasium as gym
from gym import spaces
The default version in the Kaggle notebook that I find is
print(gymnasium.__version__)
0.26.3
at this point, I restarted the notebook session and imported SB3 and sb3_contrib, as the first operation, to start testing the custom environment with SB3-PPO
repeating all the manual steps under this new context having imported the 2 mentioned libraries when I try to instantiate the custom environment I get an error that was not present without libraries importing
as if it was used a very old Gym version in which the spaces.Discret had not the attribute start (that in my case is absolutely needed). Printing again the Gym version it seems equal to the first working case
print(gym.__version__)
0.26.3
making me think, from my deep ignorance, that there could be a conflict between two existing versions of Gym/Gymnasium, the latest existing by default in the Kaggle context and explicitly imported by my code; he first somehow imported by SB libraries.
I have to note that during the pip installation of the two libraries, some errors occur in the gym wheel installation and I copy a part of them in the "Relevant log output / Error message" section.
To Reproduce
It should be very simple
open a new Kaggle notebook
import the two SB libraries and gymnasium as gym
instantiate a gymnasium environment (one of the official ones or a custom one) that uses the spaces.Discrete as action space using the start attribute.
Relevant log output / Error message
!pip install "stable-baselines3"
Here a part of the long log with the first part and last part describing the installation troubles
Building wheels for collected packages: gym
Building wheel for gym (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [476 lines of output]
running bdist_wheel
running build
running build_py
creating build
creating build/lib
creating build/lib/gym
copying gym/__init__.py -> build/lib/gym
copying gym/version.py -> build/lib/gym
copying gym/logger.py -> build/lib/gym
copying gym/error.py -> build/lib/gym
copying gym/core.py -> build/lib/gym
[.........]
for key, value in generate_requirements({extra: reqs}):
File "/opt/conda/lib/python3.10/site-packages/wheel/metadata.py", line 138, in generate_requirements
for new_req in convert_requirements(depends):
File "/opt/conda/lib/python3.10/site-packages/wheel/metadata.py", line 103, in convert_requirements
parsed_requirement = Requirement(req)
File "/opt/conda/lib/python3.10/site-packages/wheel/vendored/packaging/requirements.py", line 37, in __init__
raise InvalidRequirement(str(e)) from e
wheel.vendored.packaging.requirements.InvalidRequirement: Expected end or semicolon (after version specifier)
opencv-python>=3.
~~~^
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for gym
Running setup.py clean for gym
Failed to build gym
Installing collected packages: importlib-metadata, gym, stable-baselines3
Attempting uninstall: importlib-metadata
Found existing installation: importlib-metadata 6.0.1
Uninstalling importlib-metadata-6.0.1:
Successfully uninstalled importlib-metadata-6.0.1
Attempting uninstall: gym
Found existing installation: gym 0.26.2
Uninstalling gym-0.26.2:
Successfully uninstalled gym-0.26.2
Running setup.py install for gym ... done
DEPRECATION: gym was installed using the legacy 'setup.py install' method, because a wheel could not be built for it. pip 23.1 will enforce this behaviour change. A possible replacement is to fix the wheel build issue reported above. Discussion can be found at https://github.com/pypa/pip/issues/8368 class="ansi-yellow-fg">
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
dask-cudf 23.4.0 requires cupy-cuda11x<12.0.0a0,>=9.5.0, which is not installed.
cuml 23.4.0 requires cupy-cuda11x<12.0.0a0,>=9.5.0, which is not installed.
opentelemetry-api 1.17.0 requires importlib-metadata~=6.0.0, but you have importlib-metadata 4.13.0 which is incompatible.
dask-cudf 23.4.0 requires dask==2023.3.2, but you have dask 2023.4.0 which is incompatible.
dask-cuda 23.4.0 requires dask==2023.3.2, but you have dask 2023.4.0 which is incompatible.
cuml 23.4.0 requires dask==2023.3.2, but you have dask 2023.4.0 which is incompatible.
cmudict 1.0.13 requires importlib-metadata<6.0.0,>=5.1.0, but you have importlib-metadata 4.13.0 which is incompatible.
Successfully installed gym-0.21.0 importlib-metadata-5.2.0 stable-baselines3-1.8.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv class="ansi-yellow-fg">
same for
!pip install "stable-baselines3"
[........]
m sympy->torch>=1.11->stable-baselines3) (1.3.0)
Installing collected packages: importlib-metadata
Attempting uninstall: importlib-metadata
Found existing installation: importlib-metadata 5.2.0
Uninstalling importlib-metadata-5.2.0:
Successfully uninstalled importlib-metadata-5.2.0
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
dask-cudf 23.4.0 requires cupy-cuda11x<12.0.0a0,>=9.5.0, which is not installed.
cuml 23.4.0 requires cupy-cuda11x<12.0.0a0,>=9.5.0, which is not installed.
opentelemetry-api 1.17.0 requires importlib-metadata~=6.0.0, but you have importlib-metadata 4.13.0 which is incompatible.
dask-cudf 23.4.0 requires dask==2023.3.2, but you have dask 2023.4.0 which is incompatible.
dask-cuda 23.4.0 requires dask==2023.3.2, but you have dask 2023.4.0 which is incompatible.
cuml 23.4.0 requires dask==2023.3.2, but you have dask 2023.4.0 which is incompatible.
cmudict 1.0.13 requires importlib-metadata<6.0.0,>=5.1.0, but you have importlib-metadata 4.13.0 which is incompatible.
Successfully installed importlib-metadata-4.13.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv class="ansi-yellow-fg">
# ---------------------------------------------------------------------------
# Libraries Import
# ---------------------------------------------------------------------------
# Files Management
import gzip
import joblib
# Stocks Indicators
#import talib
# Time Management
import datetime
from datetime import datetime, timedelta
import pytz
# Math and Sci
import numpy as np
import math
from scipy.signal import argrelextrema
# Reporting
from plotly.figure_factory import create_candlestick
from plotly.subplots import make_subplots
import plotly.graph_objects as go
import matplotlib.pyplot as plt
import matplotlib
from matplotlib.pyplot import plot
from matplotlib.pylab import rcParams
from xgboost import plot_tree
import seaborn as sns
# Data Management
import pandas as pd
from sklearn.model_selection import train_test_split
from statsmodels.tsa.stattools import adfuller
from imblearn.over_sampling import SMOTE
from sklearn.preprocessing import StandardScaler
from sklearn.preprocessing import MinMaxScaler
from sklearn.preprocessing import RobustScaler
# RL ENVS
import gymnasium as gym
from gym import spaces
# Machine Learning
import torch as th
from stable_baselines3.common.monitor import Monitor
from stable_baselines3.common.results_plotter import load_results, ts2xy
from stable_baselines3 import PPO
from stable_baselines3.common import results_plotter
from stable_baselines3.common.vec_env import DummyVecEnv, SubprocVecEnv, VecNormalize,VecMonitor
from stable_baselines3.common.env_util import make_vec_env
from stable_baselines3.common.callbacks import ProgressBarCallback
from sb3_contrib import RecurrentPPO
from stable_baselines3.common.evaluation import evaluate_policy
Checklist
[X] I have checked that there is no similar issue in the repo
🐛 Bug
I am creating a custom environment, but from my understanding, the problem is due to conflicts with gym/gymnasium releases. This is the context:
as if it was used a very old Gym version in which the spaces.Discret had not the attribute start (that in my case is absolutely needed). Printing again the Gym version it seems equal to the first working case
making me think, from my deep ignorance, that there could be a conflict between two existing versions of Gym/Gymnasium, the latest existing by default in the Kaggle context and explicitly imported by my code; he first somehow imported by SB libraries.
I have to note that during the pip installation of the two libraries, some errors occur in the gym wheel installation and I copy a part of them in the "Relevant log output / Error message" section.
To Reproduce
It should be very simple
Relevant log output / Error message
System Info
As already described in a new Kaggle notebook
besides
Checklist