【问题标题】:How to import pydotplus in spyder 3.6如何在 spyder 3.6 中导入 pydotplus
【发布时间】:2017-08-14 19:53:36
【问题描述】:

我目前在 Windows 8 操作系统上使用 spyder 3.6,每当我运行此代码时 它显示一个错误

文件“”,第 12 行,在 导入pydotplus

ModuleNotFoundError: 没有名为“pydotplus”的模块

这里是代码

import pydotplus 
dot_data = tree.export_graphviz(clf, out_file=None) 

graph = pydotplus.graph_from_dot_data(dot_data) 

graph.write_pdf("iris.pdf") 

from IPython.display import Image  
dot_data = tree.export_graphviz(clf, out_file=None,feature_names=iris.feature_names,  

class_names=iris.target_names,  

filled=True, rounded=True,  

special_characters=True)

graph = pydotplus.graph_from_dot_data(dot_data)  

Image(graph.create_png())

【问题讨论】:

  • 好吧,你应该先安装那个模块。
  • 但是你能告诉我如何安装它吗?我在网上找不到文档。您能帮忙吗?
  • 您是否尝试过在 Stack Overflow 上进行搜索?我设法找到了这个:stackoverflow.com/questions/10729116/…
  • 我已经安装了谢谢你的帮助。但我无法安装 GraphViz.StackOverflow 说 pip install GraphViz。但它在我的 Windows PowerShell 上显示错误说“无法导入名称'main'”。
  • 您正在运行的确切命令是什么以及 exact 错误消息是什么?

标签: python spyder


【解决方案1】:

也许尝试使用 conda....

我在使用 pip install graphviz 并在 Jupyter 中显示绘图时遇到了同样的问题。问题是执行pip install ... 实际上并没有安装GraphViz。请参阅 PyPi (graphviz 0.7 : Python Package Index) 上的文档;您还必须安装 Graphviz:

此软件包有助于在 Python 中以 Graphviz 图形绘制软件 (repo) 的 DOT 语言创建和呈现图形描述。

...

安装

本包运行于Python 2.7,3.3+,使用pip安装:

$ pip install graphviz

要渲染生成的DOT源代码,还需要安装Graphviz(下载页面)。

这对我有用(同样,使用 Jupyter,未在 Spyder 中测试)。

$ conda install python-graphviz
# Fetching package metadata .............
# Solving package specifications: 

# The following NEW packages will be INSTALLED:

#     graphviz:        2.38.0-3      bioconda
#     python-graphviz: 0.5.2-py36_0          

然后,在 Jupyter 中:

import pydotplus 

d_tree = tree.DecisionTreeClassifier()
d_tree.fit(X_scaled, y)

dot_data = tree.export_graphviz(d_tree,
                                out_file=None,
                                filled=True,
                                rounded=True,
                                special_characters=True)  
graph = pydotplus.graph_from_dot_data(dot_data)  

from IPython.display import Image 
Image(graph.create_png()) 

【讨论】:

    猜你喜欢
    • 2018-12-23
    • 2018-12-07
    • 1970-01-01
    • 2015-02-20
    • 2017-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多