AminHP / gym-anytrading

The most simple, flexible, and comprehensive OpenAI Gym trading environment (Approved by OpenAI Gym)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Module not found error when running ipynb files / jupyiter notebooks

djarami opened this issue · comments

I feel like a noob and I've spent a bunch of time trying to run your readme and example ipynb files and I keep getting the following error via visual studio code with juypiter extension or regular jupyter notebooks.

image

I've upgraded and tried various versions of python - currently on python3.10.9.
I'm on a mac book pro 13inch M1 2020 bunning Ventura 13.1.

This seems like a really good project and I would love to get it running on my machine.

Any help would be appreciated.

Hi @djarami ,
It seems you didn't install the gym package. It should have been installed inherently by installing the gym-anytraing. Please try this:

pip install gym-anytrading
pip install 'gym==0.21'

I still get the same error when I try running in jupyter notebooks or from visual studio code with jupyter enabled.
Interestingly, I manually ran python3 from the terminal and typed each of the imports and the env command and I didn't get any errors.
image
Very weird. Something about the environment and how it imports the libraries - can't seem to find them....
I've had some hits on stack overflow, but nothing has gotten me past this. Any additional thoughts would be welcome.

commented

getting this error when trying to import gym-anytrading

import gym
import gym-anytrading
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
c:\dev\Python\Mastermind\mastermind\training\Reinforcement_Learning_with_gym_anytrading.ipynb Cell 3 in <cell line: 3>()
      [1](vscode-notebook-cell:/c%3A/dev/Python/Mastermind/mastermind/training/Reinforcement_Learning_with_gym_anytrading.ipynb#X26sZmlsZQ%3D%3D?line=0) # Gym stuff
      [2](vscode-notebook-cell:/c%3A/dev/Python/Mastermind/mastermind/training/Reinforcement_Learning_with_gym_anytrading.ipynb#X26sZmlsZQ%3D%3D?line=1) import gym
----> [3](vscode-notebook-cell:/c%3A/dev/Python/Mastermind/mastermind/training/Reinforcement_Learning_with_gym_anytrading.ipynb#X26sZmlsZQ%3D%3D?line=2) import gym_anytrading
      [5](vscode-notebook-cell:/c%3A/dev/Python/Mastermind/mastermind/training/Reinforcement_Learning_with_gym_anytrading.ipynb#X26sZmlsZQ%3D%3D?line=4) # Stable baselines - rl stuff
      [6](vscode-notebook-cell:/c%3A/dev/Python/Mastermind/mastermind/training/Reinforcement_Learning_with_gym_anytrading.ipynb#X26sZmlsZQ%3D%3D?line=5) from stable_baselines3.common.vec_env import DummyVecEnv

File c:\ProgramData\Anaconda3\lib\site-packages\gym_anytrading\__init__.py:1, in <module>
----> 1 from gym.envs.registration import register
      2 from copy import deepcopy
      4 from . import datasets

ModuleNotFoundError: No module named 'gym.envs.registration'

@djarami

You should select the proper kernel in VSCode (from the top menu bar). I think the current kernel is not the one you used in the python shell.

@Karlheinzniebuhr
You might also have the same issue with the VSCode Jupyter kernel if you're sure you installed everything correctly.

commented

I had the correct kernel but somehow there were conda conflicts. After creating a new conda environment and installing gym and gym-anytrading again the error resolved