Reputation: 23
I am a newbie in Python and I wanted to run some reinforcement learning algorithms with Python using AI Gym: https://github.com/openai/gym
I want to use tensorflow so I made a python 3.5 environment called "tensorflow" with Anaconda and installed it there. In the same environment, I installed AIgym using
pip install gym
from the Anaconda prompt. With
conda list
I can see "gym" as a package installed in that environment, but in Anaconda Navigator it is not listed (neither in the "tensofrflow" environment or anywhere else.
Anyhow if I try to do
import gym
I get
No module named 'gym'
I am sure I have the Anaconda interpreter selected in the project configurations. I also tried
pip install gym
from the regular command-line prompt but it still would refuse to find 'gym'.
One suggestion was to include the Anaconda path to the system's Python PATH. I am not sure how to do this correctly. Most advice is for Linux and I use Windows 10. Is it the path of the python.exe inside the anaconda folder? I've seen people trying
export PATH=C:/path/anaconda:$PATH
but export is not recognized for me in any command prompt.
which python
is also not recognized in order to check which python is being used. I also tried adding the anaconda path to the system path (This PC > Advanced > Environment Variables > System Variables > Path) but no dice.
Any suggestions would be appreciated.
--Update 1--
Thomas, thanks for your answer. I have tried what you suggested - tried importing gym from the python in-line interpreter from within the anaconda prompt/environment, and it worked!
In pyCharm, though, even while I am sure I have the Anaconda interpreter selected for the project, it doesn't work.
--Update 2-- I can see my envs and path but how exactly do you add an env in pyCharm? The method I have been using was, configure the project to use the Anaconda interpreter and switch environments from the anaconda prompt. A search gives the same answer.
It is strange because I have tensorflow installed only in my tensorflow environment, and tensorflow itself imports without problem, as you can see here:
Thus the tensorflow environment must be active.
Thanks in advance!
Upvotes: 1
Views: 1512
Reputation: 2656
In your cmd-example, you're using an environment called tensorflow, and not the "root" (aka default) environment. You can add that same environment to PyCharm, and use that instead.
If you're unsure of where the environment is located you can use the conda command conda env list
, i.e.:
(tensorflow) C:\Users\Riel> conda env list
That will print a list of the installed Anaconda environments and their locations. Find your tensorflow environment and add it to PyCharm.
When I do it on my system, I get this output:
# conda environments:
#
benv E:\Anaconda3\envs\benv
game E:\Anaconda3\envs\game
ml E:\Anaconda3\envs\ml
py26 E:\Anaconda3\envs\py26
py27 E:\Anaconda3\envs\py27
py33 E:\Anaconda3\envs\py33
py34 E:\Anaconda3\envs\py34
py35 E:\Anaconda3\envs\py35
py36 E:\Anaconda3\envs\py36
root * E:\Anaconda3
To add the environment to PyCharm, select from the menu bar:
File -> Settings.. -> Project Interpreter -> Click the cog wheel -> Add Local
Then find the folder of your tensorflow environment and the python.exe-file in it and add it, which according to your image, is G:\Programs\Anaconda\envs\tensorflow\python.exe
(See image below)
Upvotes: 2