Keras没有模块命名模型

时间:2017-06-18 07:24:23

标签: python keras

尝试使用虚拟环境在MacOSX中运行Keras

版本

  • MacOSX:10.12.4(16E195)
  • Python 2.7

疑难解答

  • 重新创建Virtualenv
  • 重新安装keras

日志

(venv) me$sudo pip install --upgrade keras

Collecting keras
Requirement already up-to-date: six in /Library/Python/2.7/site-packages/six-1.10.0-py2.7.egg (from keras)
Requirement already up-to-date: pyyaml in /Library/Python/2.7/site-packages (from keras)
Requirement already up-to-date: theano in /Library/Python/2.7/site-packages (from keras)
Requirement already up-to-date: numpy>=1.9.1 in /Library/Python/2.7/site-packages (from theano->keras)
Requirement already up-to-date: scipy>=0.14 in /Library/Python/2.7/site-packages (from theano->keras)
Installing collected packages: keras
Successfully installed keras-2.0.5

(venv) me$ python -c "import keras; print(keras.__version__)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named keras

1 个答案:

答案 0 :(得分:2)

这里的根本问题是当你使用sudo时,pip指向全局的系统级python而不是virtual-env python。这就是为什么在没有sudo的情况下安装时,它可以无缝地为您工作。你可以通过在virtualenv中运行sudo pip install --upgrade keras然后在virtualenv之外运行python -c "import keras; print(keras.__version__)"来检查这一点。