9

enter image description here

Can't import gym;

ModuleNotFoundError: No module named 'gym'
Albert Einstein
  • 7,472
  • 8
  • 36
  • 71
yyt
  • 91
  • 1
  • 1
  • 2

5 Answers5

7

It seems to me that you're trying to use https://pypi.org/p/gym.

You'd want to run in the terminal (before typing python, when the $ prompt is visible):

pip install gym

After that, if you run python, you should be able to run import gym.

pradyunsg
  • 18,287
  • 11
  • 43
  • 96
3

I see that you're installing gym, so

pip install gym 

is unnecessary.

Please, try:

import sys
sys.path.append('path')

where path is directory with gym module.

  • how can i find the path? – yyt May 29 '18 at 00:36
  • I think this works but is there anyway so that I could avoid setting the path every time? – yyt May 29 '18 at 12:16
  • I make research and I think it is issue with anaconda, some people have the same problem like you: https://github.com/stevenpjg/ddpg-aigym/issues/9, the last question 8 hours ago. –  May 31 '18 at 15:44
  • Thank you so much! I'll go with it for now then! – yyt May 31 '18 at 15:52
  • Can you select my answser as the best? Thanks! –  May 31 '18 at 16:30
  • One can find the path of the gym package in conda prompt with: `pip show gym` under the description: `Location: `. – a.t. Oct 20 '20 at 10:23
2

run this:

pip install gym

Then run your "import gym" again.

ruxtain
  • 146
  • 2
  • 12
  • Yutongs-MBP:~ yutongyan$ python Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 12:04:33) [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import gym Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'gym' >>> – yyt May 29 '18 at 00:42
  • That's what I got :( – yyt May 29 '18 at 00:43
1

As you are using Anaconda as your package manager, use this to install gym

conda install -c conda-forge gym

Chandan
  • 430
  • 6
  • 9
0

this works for me to hope its work for you also!!

pip install --user gym
Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108