使用: 沃森工作室 带有Spark的Python 3.5 Python笔记本:https://gist.github.com/anonymous/ea77f500b4fd80feb69fadb470fca235
此部分显示错误:
from IPython.display import Image
import pydotplus
dot_data = tree.export_graphviz(regr, out_file=None, feature_names = X_train.columns.values ,filled=True)
graph = pydotplus.graph_from_dot_data(dot_data)
给出错误: ImportError:没有名为“ pydotplus”的模块
解决方案 是否确实有另一个环境已安装此模块? 要么 有没有办法将这个python模块安装/添加到现有的运行时?
答案 0 :(得分:1)
在IBM Cloud文档中找到答案。
https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/importing-libraries.html
在Apache Spark上安装自定义库和软件包 上次更新时间:2019年3月1日 2
在Watson Studio中将Apache Spark与笔记本关联时,会包含许多预安装的库。在安装库之前,请检查预装库的列表。从笔记本单元运行适当的命令:
Python: !pip list --isolated
R: installed.packages()
如果未列出所需的库,或者要在笔记本中使用Scala库,请使用以下各节中的步骤进行安装。库软件包的格式取决于编程语言。 使用Scala库
Scala笔记本的库通常打包为Java™归档(JAR)文件。 临时缓存库
Scala笔记本的库未安装到Spark服务。而是在下载它们时将它们缓存起来,并且仅在笔记本计算机运行时可用。
To use a single library without dependencies, from a public web server:
Locate the publicly available URL to the library that you want to install. If you create a custom library, you can post it to any publicly available repository, such as GitHub.
Download the library you want to use in your notebook by running the following command in a code cell:
%AddJar URL_to_jar_file
To use a library with dependencies, from a public Maven repository:
Add and import a library with all its dependencies by running the following command. You need the groupId, artifactId, and version of the dependency. For example:
%AddDeps org.apache.spark spark-streaming-kafka_2.10 1.1.0 --transitive
要永久安装库
如果要使文件可用于Spark-Submit作业和Scala内核,或者想通过其他内核通过Java桥访问文件,则可以将库永久安装到〜/ data / libs /。使用Python或R中的JDBC驱动程序。
已安装库到〜/ data / libs /的文件路径因库所需的Scala版本而异:
Use ~/data/libs/ for libraries that work with any Scala version.
Use ~/data/libs/scala-2.11/ for libraries that require Scala 2.11. The Scala kernel for Spark 2.1 uses Scala 2.11.
要安装库,请执行以下操作:
Locate the publicly available URL to the library that you want to install.
Download the library you want to install permanently into ~/data/libs/ by running the following command in a Python notebook:
!(cd ~/data/libs/ ; wget URL_to_jar_file)
要安装Python库
Use the Python pip package installer command to install Python libraries to your notebook. For example, run the following command in a code cell to install the prettyplotlib library:
!pip install --user prettyplotlib
The --user flag installs the library for personal usage rather than the global default. The installed packages can be used by all notebooks that use the same Python version in the Spark service.
Use the Python import command to import the library components. For example, run the following command in a code cell:
import prettyplotlib as ppl
Restart the kernel.
加载R包
Use the R install.packages() function to install new R packages. For example, run the following command in a code cell to install the ggplot2 package for plotting functions:
install.packages("ggplot2")
The imported package can be used by all R notebooks running in the Spark service.
Use the R library() function to load the installed package. For example, run the following command in a code cell:
library("ggplot2")
You can now call plotting functions from the ggplot2 package in your notebook.