Stable Baselines doesn't work with tensorflow
Asked Answered
A

3

5

So I recently got back into machine learning, and decided to start the Kaggle course for "ConnectX" (https://www.kaggle.com/learn/intro-to-game-ai-and-reinforcement-learning). I am trying to do lesson 4, in which I use stable-baselines + Tensorflow to make an AI. The problem is, I can't seem to use stable-baselines properly as it gives me an error instantly as I try to import it. Here is the error message:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-13-f5986851ce81> in <module>
      1 import os
----> 2 from stable_baselines.bench import Monitor
      3 from stable_baselines.common.vec_env import DummyVecEnv
      4 
      5 # Create directory for logging training information

~\Anaconda3\lib\site-packages\stable_baselines\__init__.py in <module>
----> 1 from stable_baselines.a2c import A2C
      2 from stable_baselines.acer import ACER
      3 from stable_baselines.acktr import ACKTR
      4 from stable_baselines.deepq import DQN
      5 from stable_baselines.her import HER

~\Anaconda3\lib\site-packages\stable_baselines\a2c\__init__.py in <module>
----> 1 from stable_baselines.a2c.a2c import A2C

~\Anaconda3\lib\site-packages\stable_baselines\a2c\a2c.py in <module>
      5 import tensorflow as tf
      6 
----> 7 from stable_baselines import logger
      8 from stable_baselines.common import explained_variance, tf_util, ActorCriticRLModel, SetVerbosity, TensorboardWriter
      9 from stable_baselines.common.policies import ActorCriticPolicy, RecurrentActorCriticPolicy

~\Anaconda3\lib\site-packages\stable_baselines\logger.py in <module>
     15 from tensorflow.python.util import compat
     16 
---> 17 from stable_baselines.common.misc_util import mpi_rank_or_zero
     18 
     19 DEBUG = 10

~\Anaconda3\lib\site-packages\stable_baselines\common\__init__.py in <module>
      2 from stable_baselines.common.console_util import fmt_row, fmt_item, colorize
      3 from stable_baselines.common.dataset import Dataset
----> 4 from stable_baselines.common.math_util import discount, discount_with_boundaries, explained_variance, \
      5     explained_variance_2d, flatten_arrays, unflatten_vector
      6 from stable_baselines.common.misc_util import zipsame, set_global_seeds, boolean_flag

~\Anaconda3\lib\site-packages\stable_baselines\common\math_util.py in <module>
      1 import numpy as np
----> 2 import scipy.signal
      3 
      4 
      5 def safe_mean(arr):

~\Anaconda3\lib\site-packages\scipy\signal\__init__.py in <module>
    287 
    288 """
--> 289 from . import sigtools, windows
    290 from .waveforms import *
    291 from ._max_len_seq import max_len_seq

~\Anaconda3\lib\site-packages\scipy\signal\windows\__init__.py in <module>
     39 """
     40 
---> 41 from .windows import *
     42 
     43 __all__ = ['boxcar', 'triang', 'parzen', 'bohman', 'blackman', 'nuttall',

~\Anaconda3\lib\site-packages\scipy\signal\windows\windows.py in <module>
      5 
      6 import numpy as np
----> 7 from scipy import linalg, special, fft as sp_fft
      8 
      9 __all__ = ['boxcar', 'triang', 'parzen', 'bohman', 'blackman', 'nuttall',

~\Anaconda3\lib\site-packages\scipy\special\__init__.py in <module>
    631 from .sf_error import SpecialFunctionWarning, SpecialFunctionError
    632 
--> 633 from . import _ufuncs
    634 from ._ufuncs import *
    635 

ImportError: DLL load failed: The specified module could not be found.

It looks like something's wrong with scipy, but I have no idea what I can do to fix it. This error happens even if I run import stable_baselines. Here is the code I run to create the virtual environment (BTW, this is in PowerShell b/c that is what Jupyter Lab gives me):

python -m venv myenv
.\myenv\Scripts\Activate.ps1
pip install stable-baselines

NOTE: I don't know if this is of any significance, but when I install stable-baselines, an error appears: ERROR: gym 0.17.2 has requirement cloudpickle<1.4.0,>=1.2.0, but you'll have cloudpickle 1.5.0 which is incompatible.

PS: I found the same issue here, but I have no idea how they fixed it. The answer just says "I used anaconda", but there is no stable-baselines package in anaconda! I tried installing tensorflow from anaconda and stable-baselines from pip, but it still gave the same error.

LAST EDIT: Looks like this issue is on . imports and is only valid in jupyter notebook (doesn't have anything to do with tensorflow - it works fine in Python CLI). I have explained it in my new question about opencv here.

~ Ayush

Accursed answered 5/7, 2020 at 0:6 Comment(1)
This is working for me Feb 2023 - tensorflow==2.11.0, stable-baselines3==1.2.0 | from stable_baselines3.common.vec_env import DummyVecEnvSin
O
7

The stable baselines site claims they do not support tf2.X yet. So that might be your problem

Try the following,

pip install tensorflow==1.14.0
pip install stable-baselines[mpi]==2.10.0

They seem to work together for me to this day(Sept 4th, 2020).

I know this might be a little late but I found your question now and decided to answer it as best as I could. Good luck!

Obregon answered 4/9, 2020 at 18:33 Comment(0)
S
3

If you are looking specifically for a TF2 version of Stable Baselines, check one of these (experimental) forks:

Alternatively, try Stable Baselines 3 (currently in beta), which is based on PyTorch instead of Tensorflow and is intended to replace the current TF1-based SB2 version:

Sorcha answered 14/10, 2020 at 13:25 Comment(0)
I
1

import stable_baselines doesn't work.

import stable_baselines3 works.


For installing Stable-baselines, you can use

  • conda install -c conda-forge stable-baselines3 if you use Anaconda
  • pip install stable-baselines if you want to install using PIP
Irresolvable answered 10/1, 2022 at 6:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.