9

I installed pycharm-2016.1.4 in my PC running Ubuntu 14.04. I have installed Keras (a Python package) using pip install keras and PyCharm can find it before. But it cannot find Keras now. I do not modify any settings, so this problem may be wired. My Python version is Python 2.7.

enter image description here

I use pip list to verify that I have Keras installed:

enter image description here

But check this package in PyCharm by using: Settings -> Project -> Project Interpreter. Keras is NOT in the package list. (The interpreter used is the same as the result of which python in terminal).

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Dong Li
  • 520
  • 2
  • 7
  • 18

6 Answers6

9

This is strange, but you can install Keras directly through Pycharm.

You can follow this steps:

  • Go to Settings -> Project -> Project Interpreter
  • Click on plus icon in the top-right corner
  • Search Keras and press on Install Package

Please let me know if this procedure solve your issue.

Giordano
  • 5,422
  • 3
  • 33
  • 49
  • I have tried method as you say before, but **NO** packages in the list. I tried your answer just now and no packages as well. Steps: Settings -> Project -> Project Interpreter, click the green "add" button, search keras but no packages in the list. – Dong Li Sep 24 '16 at 06:12
  • Do you use a virtualenv? Are you sure that you selected the correct Interpreter? – Giordano Sep 24 '16 at 06:18
  • I do not use virtualenv. I only have one interpreter: anaconda's python-2.7. – Dong Li Sep 24 '16 at 06:28
  • Moreover, I find I cannot install ant package using your method. Maybe the **install package** in my pycharm crash? – Dong Li Sep 24 '16 at 06:31
  • Hi, I have the same problem, and I use a virtualenv, @Giordano, can you please help me with installation of Keras using PyCharm? Everytime I try to install it using the above method, PyCharm shows me an error "40:490 execution erro:The directory '/Users/varij/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled." – Varij Kapil May 20 '17 at 10:54
  • Hi @varijkap, seems that you have some permission problems with the folder /Users/varij/Library/Caches/pip/http or its parent. – Giordano May 20 '17 at 10:59
  • But normal pip operations are successful, I am able to install keras without sudo through the terminal, Anyways, I solved the issue by changing the Project interpreter directory by following [this](http://stackoverflow.com/a/35141307/2228983) answer – Varij Kapil May 20 '17 at 11:10
2

I do not know what happened, but the problem solved with the following steps.

  1. Uninstall old keras
  2. Re-install keras: pip install keras

Then I can import keras in pycharm.

NOTE: It is strange since I have keras installed but cannot find it in Project Interpreter's package list.

Dong Li
  • 520
  • 2
  • 7
  • 18
2

Use

import tensorflow.python.keras

instead.

  • This is a 6 year old question, do you mind putting an explanation as to why the above works? (I ask because others have flagged the answer) – Michael S. Aug 19 '22 at 19:52
0

To clearify Giordano's answer:

  1. You should have installed tensorflow or any other framework where keras can be used on top of.
  2. Create a virtualenv and set this as your project interpreter. This is a working solution for me: Installing tensorflow on Pycharm (Mac)
  3. Got to preferences -> Project: -> Project Interpreter
  4. Click on the plus sign on the bottom left corner
  5. Search Keras and install the package.
David Joos
  • 926
  • 11
  • 16
0

My solution:

if you ever have installed in python:

  • Go to File->Settings->Project->Project Interpreter
  • Click the gear-> Add..->System interpreter
  • Choose the python version that have installed keras
0

I am running through a training video series and, with Conda installed on my Centos 7 system, I could not get Keras to load properly. My solution was to use VirtualEnv for my Python Interpreter. I followed the steps here: https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html#add_new_project_interpreter

  • Can you include the steps you followed in your answer? If the link you included ever stops working, your answer loses it's value. – quicklikerabbit Sep 10 '20 at 17:10