如何在 GCP Dataproc 中为 Pyspark 设置 Jupyter 默认用户

How to set the Jupyter default user for Pyspark in GCP Dataproc

在连接到 GCP Spark 集群的 Jupyter notebook 中,单元 !pip3 install pyLDAvis==3.2.1 工作,但给出警告:

WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. 
It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

此警告并非 pyLDAvis 独有,其他软件包 - 甚至 numpy - 也会发出相同的警告。

运行 作为 root 的笔记本不应该是默认的。如何将笔记本中的默认用户设置为 singhj 而不是 root?我在 IPython Configuration and customization 中搜索了任何提示。

配置:GCP Dataproc 中的全新集群,默认 Jupyter notebook,没有任何自定义。

Dataproc 集群中的 Jupyter 服务器 运行 由文件 /usr/lib/systemd/system/jupyter.service.

中定义的 systemd 服务提供

如果您想将用户更改为 运行,那么您可以修改该文件并将 User=root 行替换为您想要的用户名(例如 User=singhj 在你的例子中)。

然后,更新文件后,通过 运行以 root 身份执行以下命令重新启动 systemd 服务:

systemctl daemon-reload 
systemctl restart jupyter

如果您想自动执行此操作,您可以编写一个 initialization action 以在创建集群时进行更改。