4
votes

I can't import Keras in PyCharm IDE on a Mac. I have tried installing and uninstalling Keras using both pip, pip3, conda, and easy install, but none worked. I have tried changing interpreters (Python 2.7 and 3.6) but neither worked.

In a terminal, when I run:

pip3 list | grep -i keras

I get:

Keras 2.2.2
Keras-Applications 1.0.4
Keras-Preprocessing 1.0.2

I think this means that my Keras installation was successful. I have also checked my environment with:

python3 -c 'import sys, pprint; pprint.pprint(sys.path)'

I get:

'/anaconda3/lib/python36.zip', '/anaconda3/lib/python3.6', '/anaconda3/lib/python3.6/lib-dynload', '/anaconda3/lib/python3.6/site-packages', '/anaconda3/lib/python3.6/site-packages/aeosa']

I have tried running:

python -c "import keras"

I get:

Using TensorFlow backend.

But when I run/import Keras on the PyCharm IDE, I get:

ModuleNotFoundError: No module named 'keras'

What should I do to run Keras on a Mac with PyCharm 3.6?

2
"Using TensorFlow backend." means keras is imported correctly.Dr. Snoopy
Sorry I have edited my post, the problem is when I import keras in IDE i get import error.dm5
can you check python interpreter in pycharm, and while selecting interpreter you can see list of packages installed. check whether keras is there or not @dm5Asif Mohammed
I just run pip list, keras packages are installed @Asif Mohameddm5
try opening terminal in pycharm. and check sys.path is correct or not. you might have picked wrong interpreter. @dm5.Asif Mohammed

2 Answers

1
votes

When you start a project in PyCharm, there is an option to use an existing virtual environment or create a new virtual environment. If nothing mentioned while creating the project, new virtual environment will be created. If that is the case, there is no Keras in the new environment which is possibly your issue. It will be better to do this installation in some virtual environments and use it accordingly in Pycharm.

0
votes

I think this has a relation with the environment the pycharm using try to install Keras using pycharm terminal

in pycharm terminal apply the following

pip install Keras