"No module named numpy..." google-data-proc 错误,如何升级 google-data-proc 上的 numpy?

"No module named numpy..." error on google-data-proc , how to upgrade numpy on google-data-proc?

当我 运行 我的笔记本在 Google-Cloud-Data-Proc

上时,我一直收到这个错误
import numpy as np
ImportError: ('No module named numpy', <function _parse_datatype_json_string at 0x7fc294e25230>.......

但是当 运行 在本地使用相同的 python 2.7

时不会出现错误

我发现我本地的版本是 numpy.version.version '1.11.1'

但在 google-data-proc 上它更旧 **'1.8.2' **

如其他答案所述ImportError: No module named numpy - Google Cloud Dataproc when using Jupyter Notebook我试过这个来升级

 import sys

sys.path.append('/usr/lib/python2.7/dist-packages')

os.system("sudo apt-get install python-pandas -y")
os.system("sudo apt-get install python-numpy -y")
os.system("sudo apt-get install python-scipy -y")
os.system("sudo apt-get install python-sklearn -y")

import pandas
import numpy
import scipy
import sklearn

我还是1.8.2版本

pip 命令对 google-data-proc

没有权限

用 sudo 试过 pip,也没有用。

IOError: [Errno 13] Permission denied: '/usr/local/bin/miniconda/lib/python2.7/site-
packages/easy-install.pth'
my-user-name@cluster-name-1-m:~$ sudo pip install numpy
sudo: pip: command not found

编辑:我们现在 added a metadata option JUPYTER_CONDA_PACKAGES to automatically pre-install packages through conda during the Jupyter setup. As now covered by the examples,安装软件包的首选方法是:

gcloud dataproc clusters create my-cluster \
    --initialization-actions gs://dataproc-initialization-actions/jupyter/jupyter.sh \
    --metadata JUPYTER_CONDA_PACKAGES=numpy:pandas:scikit-learn:scipy

在没有使用此元数据值的情况下,下面的历史答案供后代和更多内部详细信息使用:

Dataproc 的 jupyter 初始化操作也会安装 conda,因此在您的主节点上您可以 运行:

sudo su
conda install numpy

根据它的使用方式,您可能还需要在工作节点上使用它;您可以自定义主 jupyter.sh 脚本,在 /dataproc-initialization-actions/conda/bootstrap-conda.sh 行之后的任何位置添加行 conda install numpy 并将您的自定义初始化操作重新上传到 GCS 某处,以指定而不是 gs://dataproc-initialization-actions/jupyter/jupyter.sh自动将其安装在您的部署中。类似于:

gsutil cp gs://dataproc-initialization-actions/jupyter/jupyter.sh .
echo "conda install numpy >> jupyter.sh"
gsutil cp jupyter.sh gs://my-bucket/jupyter_with_numpy.sh
gcloud dataproc clusters crreate my-cluster \
    --initialization-actions gs://my-bucket/jupyter_with_numpy.sh 

最后,您还可以使用 Jupyter UI 中内置的包管理器来浏览和安装 conda 包: