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

issue such command 'mermaid' cannot be run #4

Closed
thjensuit opened this issue Apr 7, 2017 · 13 comments
Closed

issue such command 'mermaid' cannot be run #4

thjensuit opened this issue Apr 7, 2017 · 13 comments

Comments

@thjensuit
Copy link

thjensuit commented Apr 7, 2017

Hi everyone,

I have installed sphinxcontrib-mermaid extension as the following guide: https://github.com/mgaitan/sphinxcontrib-mermaid

in a "mermaid-template.rst" file I made a code such below

Mermaid Template
#################

.. mermaid::

    graph LR
    A[Hard edge] -->B(Round edge)
        B --> C{Decision}
        C -->|One| D[Result one]
        C -->|Two| E[Result two]

When running sphinx that threw out a warning such below and the flowchart was not generated:

warning: command 'mermaid' cannot be run (needed for mermaid output), check the mermaid_cmd setting.

After that I still installed mermaid-cli as the following guide: https://knsv.github.io/mermaid/#mermaid-cli8

But the warning was still exists and was not generated the flowchart.
May anyone help me in this case?

P.S:

  • OS: window 8.1
  • Sphinx: 1.4.8
  • PhantomJS: 2.1.1
  • Mermaid setup success with command such as mermaid template.mmd or mermaid --help

Thank you for your watching,
Best Regards

@thjensuit
Copy link
Author

Quoted from @mgaitan

hey @thjensuit, please open this issue in the sphinx-mermaid's tracker, https://github.com/mgaitan/sphinxcontrib-mermaid/issues

meanwhile, could you find the absolute path of mermaid command, and set this as the mermaid_cmd variable in your project's conf.py?

@thjensuit
Copy link
Author

thjensuit commented Apr 7, 2017

Hi @mgaitan,

meanwhile, could you find the absolute path of mermaid command, and set this as the mermaid_cmd variable in your project's conf.py?

I have set on $PATH of the OS before.

You mean that I set within conf.py such:
mermaid_cmd = 'C:\\Users\\thjen_000\\AppData\\Roaming\\npm\\node_modules\\mermaid'

Then when running it throws out a exception as below:

exception

Correct me if I make a wrong way.

@mgaitan
Copy link
Owner

mgaitan commented Apr 20, 2017

are you sure there is no a missing .exe at the end?

Do this:

  • save you diagram markup in a file test.mmd

Then try to compile it using vanilla mermaid-cli from the command line

C:\Users\thjen_000\AppData\Roaming\npm\node_modules\mermaid.exe test.mmd

does it work?

@mgaitan mgaitan closed this as completed Nov 22, 2017
@tylerlong
Copy link

Mermaid command line has been replaced by https://github.com/mermaidjs/mermaid.cli

@mgaitan mgaitan reopened this Mar 19, 2018
@MatinF
Copy link

MatinF commented Apr 9, 2020

I believe the issue I'm facing is similar to this one potentially

@mgaitan
Copy link
Owner

mgaitan commented Apr 9, 2020

@MatinF please, help to debug this. mermaid's cli is working on your system, outside this plugin?

@MatinF
Copy link

MatinF commented Apr 9, 2020

Yes I can use it as per their testing examples to convert a mermaid file outside of the Sphinx context using the cli without issues

@mgaitan
Copy link
Owner

mgaitan commented Apr 9, 2020

give me an example of a command line, please

@MatinF
Copy link

MatinF commented Apr 9, 2020

I've tested both with global and local install. For example, if I have the below content:

graph TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[Car]

inside a file, test.mmd, then I can run below via the command prompt:

mmdc -i test.mmd -o output.png

In my Sphinx conf.py I've added the below, with the path being to the local installation of mmdc:

extensions = [
    "sphinxcontrib.mermaid",
]

mermaid_cmd = "C:\\Users\\marti\\Documents\\sphinx-test\\node_modules\\.bin\\mmdc"
mermaid_output_format = "png"

I've also raised this separately in issue #42 .

best,
Martin

@mgaitan
Copy link
Owner

mgaitan commented Apr 9, 2020

try this. set the command line as a raw string

mermaid_cmd = r"C:\Users\marti\Documents\sphinx-test\node_modules\.bin\mmdc"

if that fails, try to modify the Popen, here

https://github.com/mgaitan/sphinxcontrib-mermaid/blob/master/sphinxcontrib/mermaid.py#L172-L174

passing and additional argument shell=True

@MatinF
Copy link

MatinF commented Apr 9, 2020

Hi mgaitan, the first part did not work - but adding shell=True to the file you recommended did resolve it! :-) Thanks a ton!

@MatinF
Copy link

MatinF commented Apr 9, 2020

One other, perhaps somewhat related, question: Now that I have the basic functionality working, I was looking to try and add a custom configuration file in order to tweak the width of the charts (in PNG it seems like the width is too small). To do this, I tried to create below addition to the conf.py:

mermaid_sequence_config = (
    r"C:\Users\marti\Documents\sphinx-test\docs\mermaid-config.json"
)

However, doing so results in below error log:

# Sphinx version: 3.0.0
# Python version: 3.7.3 (CPython)
# Docutils version: 0.14 
# Jinja2 version: 2.11.1
# Last messages:
#   done
#   checking consistency...
#   done
#   preparing documents...
#   done
#   writing output... [ 20%] configure/configure
#   writing output... [ 40%] index
#   writing output... [ 60%] introduction/about
#   writing output... [ 80%] introduction/about/about
#   writing output... [100%] introduction/introduction
# Loaded extensions:
#   sphinx.ext.mathjax (3.0.0) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx\ext\mathjax.py
#   sphinxcontrib.applehelp (1.0.2) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinxcontrib\applehelp\__init__.py
#   sphinxcontrib.devhelp (1.0.2) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinxcontrib\devhelp\__init__.py
#   sphinxcontrib.htmlhelp (1.0.3) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinxcontrib\htmlhelp\__init__.py
#   sphinxcontrib.serializinghtml (1.1.4) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinxcontrib\serializinghtml\__init__.py
#   sphinxcontrib.qthelp (1.0.3) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinxcontrib\qthelp\__init__.py
#   alabaster (0.7.12) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\alabaster\__init__.py
#   recommonmark (0.6.0) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\recommonmark\__init__.py
#   sphinx.ext.todo (3.0.0) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx\ext\todo.py
#   sphinx.ext.githubpages (3.0.0) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx\ext\githubpages.py
#   sphinxcontrib.mermaid (3.0.0) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinxcontrib\mermaid.py
#   sphinx_selective_exclude.eager_only (1.0.2) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx_selective_exclude\eager_only.py
#   sphinx_selective_exclude.search_auto_exclude (1.0.2) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx_selective_exclude\search_auto_exclude.py
#   sphinx_selective_exclude.modindex_exclude (1.0.2) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx_selective_exclude\modindex_exclude.py
#   romnnn_sphinx_press_theme (unknown version) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\romnnn_sphinx_press_theme\__init__.py
Traceback (most recent call last):
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx\cmd\build.py", line 280, in build_main
    app.build(args.force_all, filenames)
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx\application.py", line 348, in build
    self.builder.build_update()
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx\builders\__init__.py", line 299, in build_update
    len(to_build))
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx\builders\__init__.py", line 361, in build
    self.write(docnames, list(updated_docnames), method)
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx\builders\__init__.py", line 535, in write
    self._write_serial(sorted(docnames))
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx\builders\__init__.py", line 545, in _write_serial
    self.write_doc(docname, doctree)
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx\builders\html\__init__.py", line 597, in write_doc
    self.docwriter.write(doctree, destination)
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\docutils\writers\__init__.py", line 80, in write
    self.translate()
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx\writers\html.py", line 71, in translate
    self.document.walkabout(visitor)
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\docutils\nodes.py", line 174, in walkabout
    if child.walkabout(visitor):
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\docutils\nodes.py", line 174, in walkabout
    if child.walkabout(visitor):
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\docutils\nodes.py", line 174, in walkabout
    if child.walkabout(visitor):
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\docutils\nodes.py", line 166, in walkabout
    visitor.dispatch_visit(self)
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx\util\docutils.py", line 468, in dispatch_visit
    method(node)
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinxcontrib\mermaid.py", line 309, in html_visit_mermaid
    render_mm_html(self, node, node["code"], node["options"])
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinxcontrib\mermaid.py", line 277, in render_mm_html
    fname, outfn = render_mm(self, code, options, format, prefix)
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinxcontrib\mermaid.py", line 190, in render_mm
    json.dump(self.builder.config.mermaid_sequence_config, seq)
  File "c:\users\marti\appdata\local\programs\python\python37\lib\json\__init__.py", line 180, in dump
    fp.write(chunk)
  File "c:\users\marti\appdata\local\programs\python\python37\lib\tempfile.py", line 481, in func_wrapper
    return func(*args, **kwargs)
TypeError: a bytes-like object is required, not 'str'

Should the config be parsed in another way?

I figured maybe a simpler alternative would be to use the option mermaid_params = ["--width", "1200", "--backgroundColor", "transparent"], but it seems like the mermaid_params are not used.

@wlievens
Copy link
Contributor

Was the shell=True argument not added? I'm having trouble getting this suggestion to work.

wlievens added a commit to wlievens/sphinxcontrib-mermaid that referenced this issue Sep 24, 2020
When mermaid_cmd_shell is set to True, or the string value "true" or "True", the argument shell=True will be passed to the Popen call

This addresses the issue described in mgaitan#4
@mgaitan mgaitan closed this as completed Sep 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants