No module named keras

The problem I'm having is:

$ sudo pip install --upgrade keras

Then enter Python in the $~ directory

>>> import keras

Report No module named keras


Solution:

1. View the installation directory of keras: $ cd /

$ sudo find -name keras 

I get result with

/usr/local/lib/python2.7/dist-packages/keras

/usr/local/anaconda....tensorflow/keras

2. cd to the /usr/local/lib/python2.7/dist-packages directory:

python

>>> import keras

There is no error, so it should be a path problem, and the path "/usr/local/lib/python2.7/dist-packages" is correct

3. $ sudo vim /etc/profile

join at the end

export PYTHONPATH="/usr/local/lib/python2.7/dist-packages:$PYTHONPATH" [Note that $PYTHONPATH is not $PATH! !

(Correction of the previous error: export $PYTHONPATH="/usr/local/lib/python2.7/dist-packages:$PYTHONPATH" , with an extra $…covering face.jpg)

4. $ source /etc/profile

Then you can~


Related Posts