pytransitions / transitions

A lightweight, object-oriented finite state machine implementation in Python with many extensions
MIT License
5.49k stars 524 forks source link

examples.ipynb in repo cant generate basic state diagrams #556

Closed bbartling closed 2 years ago

bbartling commented 2 years ago

Hi,

When I try to run the example IPython notebook Graph Mixin Demo Nested.ipynb or any of the examples: AttributeError: module 'graphviz.backend' has no attribute 'ENCODING'

I've tried the steps in the repo to generate basic state diagrams:

conda install graphviz python-graphviz
pip install graphviz pygraphviz

but no luck, anaconda.org has some similar documentation to try:

To install this package with conda run one of the following: conda install -c conda-forge python-graphviz conda install -c conda-forge/label/broken python-graphviz conda install -c conda-forge/label/cf201901 python-graphviz conda install -c conda-forge/label/cf202003 python-graphviz

Where still no luck trying on both Windows and Ubuntu 20.04 with Jupyter Labs, both same issue. I also notice that the pygraphviz has some documentation PDF where they mention an executable installer for Windows before using pip.

Everything seems to install OK but no matter what I try when I run the examples IPython notebook files in the repo locally I cant render anything.

Do I have to use IPython? Would there be anything simpler by chance for example to just save a .PNG file to a directory for a basic state diagram?

Thanks for any tips.

aleneum commented 2 years ago

Unfortunately, I cannot reproduce this issue. I guess it it related to some version clash between graphviz and pygraphviz. I tested pygraphviz 1.7 without any issues. You can check the binder notebook which should work fine. I cannot do much about pygraphviz issues though. But you can try to use the graphviz backend. You need to have this package installed and a working Graphviz environment with dot in you path, so that the graphviz package can find it. Conda installs this version with conda install python-graphviz and also takes care of Graphviz as far as I remember.

To use the graphviz backend instead of the pygraphviz backend in the notebooks, you just need to add use_pygraphviz=False to the extra_args:

extra_args = dict(auto_transitions=False, initial='standing', title='Mood Matrix',
                  show_conditions=True, show_state_attributes=True, use_pygraphviz=False)

maybe this helps.

bbartling commented 2 years ago

I think its working now after I got pygraphviz properly installed referencing referencing the directions from the pygraphviz git repo for Windows OS.

Chocolatey

PS C:\> choco install graphviz

And in a cell within a Jupyter lab .ipynb running: pip install --global-option=build_ext --global-option="-IC:\Program Files\Graphviz\include" --global-option="-LC:\Program Files\Graphviz\lib" pygraphviz

And presto, I can render the example.ipynb in this repo : )