Problem installing gym

Hello,
I´m trying to run some code using Jupyter and I can´t find a way of installing gym.
This is the code:

!pip install gym==0.18
import gym

After all the "Requirement already satisfied"s (since I had already installed it) it says:


ModuleNotFoundError Traceback (most recent call last)
Input In [2], in <cell line: 2>()
1 get_ipython().system(‘pip install gym’)
----> 2 import gym

ModuleNotFoundError: No module named ‘gym’
The same happens if I try to !install gym (no version).
It worked before, however I created a new environment in Jupyter for this course and it stopped working.
I tried installing it using Terminal several ways, however, this shouldn´t be so complicated, right?
Thanks in advance.

1 Like

dear Unagi.

Thank you for your contribution to the Anaconda community.

It worked before, however I created a new environment in Jupyter for this course and it stopped working

If you create a new environment, the new PATH will be applied to Jupyter. So installed packages get lost and IPython spits out his ModuleFoundError.

Therefore, the following article was already written five years ago, and I think it will be helpful.

https://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/

Similarly, there is an article at the following URL as a precaution when using pip in the Anaconda environment, so it would be good to refer to it.

Best regards
ktsh.tanaka.2020