即使已安装Python模型(使用gcloud),也会发生ImportError

时间:2018-09-27 10:55:17

标签: python ubuntu google-cloud-platform pip gcloud

我想通过gcloud命令运行Python脚本(在Ubuntu Linux环境中)。该脚本需要安装hSpy模块:

$ python -m pip install hSpy
Requirement already satisfied: hSpy in /home/mfb/.local/lib/python2.7/site-packages
Requirement already satisfied: Django==1.3 in /home/mfb/.local/lib/python2.7/site-packages (from hSpy)

但是,当我通过gcloud运行脚本时,出现以下错误:

$ gcloud ml-engine local train --job-dir $JOB_DIR --module-name mnist_google.mnist_mlp_google_ml --package-path ./mnist_google -- --train-file ./data/mnist.pkl
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/mnt/Python/KerasTutorial/mnist_google/mnist_mlp_google_ml.py", line 15, in <module>
    import h5py    # for saving the model
ImportError: No module named h5py

有什么想法可以使gcloud环境找到hSpy Python模块吗?
我是否必须在全球安装?

修改
如评论中所述,我混淆了软件包hSpyh5py

1 个答案:

答案 0 :(得分:3)

如前所述,您的ImportError用于h5py,而不是hSpy,这是您之前安装的。

我建议您运行pip install h5py来解决此错误。