Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No write attribute under Python 3? #136

Closed
elmerehbi opened this issue Oct 10, 2016 · 4 comments
Closed

No write attribute under Python 3? #136

elmerehbi opened this issue Oct 10, 2016 · 4 comments
Assignees
Labels

Comments

@elmerehbi
Copy link

elmerehbi commented Oct 10, 2016

I have Python 3 through Anaconda.
I tried installing pydot with Anaconda but it returns the following error:

conda install pydot

The following specifications were found to be in conflict:

  • pydot
  • python 3.5*

So I installed it with pip:
pip install pydot

When I run either of graph.write_pdf("iris.pdf") or Image(graph.create_png()) I get:

list' object has no attribute 'write_pdf' or 'create_png'

Actually there's no "write" attribute to use following the dot: graph.

@elmerehbi elmerehbi changed the title No write attribute No write attribute under Python 3? Oct 10, 2016
@johnyf
Copy link
Contributor

johnyf commented Oct 10, 2016

The tests are run on Travis under both versions 2 and 3 of Python, so this is likely manipulating an instance of an object that is not a graph, but a list. My guess is that it is a list of graphs, and that it was obtained by loading some dot files. An earlier version of the API used to return a graph object when the dot file defined one graph, and a list of graphs otherwise (in the case of more graphs).

However, I found that the inhomogeneous behavior is more complex (simple is better than complex, PEP 20), so I changed it to return a list in all cases (e.g., a list containing one graph). This simplifies also user code, because there no case distinction needs to be made.

Is this how the list arises? For example, if this is a list containing a single graph, you can obtain the graph with

some_graphs = ...
assert len(some_graphs) == 1, some_graphs
(graph,) = some_graphs
graph.write_pdf('iris.pdf')

@johnyf
Copy link
Contributor

johnyf commented Oct 11, 2016

@elmerehbi did this solve the issue?

@elmerehbi
Copy link
Author

elmerehbi commented Oct 13, 2016

Thank you for the reply @johnyf.

You got it right, obviously if I am not mistaken. Here's the code I copied a few months ago from the scikit-learn website:

from sklearn.externals.six import StringIO  
import pydot 
dot_data = StringIO() 
tree.export_graphviz(clf, out_file=dot_data) 
graph = pydot.graph_from_dot_data(dot_data.getvalue()) 
graph.write_pdf("iris.pdf") 

from IPython.display import Image  
dot_data = StringIO()  
tree.export_graphviz(clf, out_file=dot_data,  
                         feature_names=iris.feature_names,  
                         class_names=iris.target_names,  
                         filled=True, rounded=True,  
                         special_characters=True)  
graph = pydot.graph_from_dot_data(dot_data.getvalue())  
Image(graph.create_png())

@johnyf johnyf added the invalid label Oct 13, 2016
@johnyf johnyf self-assigned this Oct 13, 2016
@johnyf
Copy link
Contributor

johnyf commented Oct 13, 2016

Indeed, the function pydot.graph_from_dot_data returns what dot_parser.parse_dot_data returns, which is a list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants