Qiskit / qiskit-tutorials

A collection of Jupyter notebooks showing how to use the Qiskit SDK
Apache License 2.0
2.33k stars 1.29k forks source link

pydot error for local build #1324

Closed HuangJunye closed 2 years ago

HuangJunye commented 2 years ago

Informations

What is the current behavior?

Encounter below error while trying to do a local build.

CellExecutionError in tutorials/circuits_advanced/04_transpiler_passes_and_passmanager.ipynb:
------------------
from qiskit.converters import circuit_to_dag
from qiskit.tools.visualization import dag_drawer
dag = circuit_to_dag(circ)
dag_drawer(dag)
------------------
FileNotFoundError: [Errno 2] "dot" not found in path.
FileNotFoundError: [Errno 2] "dot" not found in path.

Expand to see the detailed error log

``` Notebook error: CellExecutionError in tutorials/circuits_advanced/04_transpiler_passes_and_passmanager.ipynb: ------------------ from qiskit.converters import circuit_to_dag from qiskit.tools.visualization import dag_drawer dag = circuit_to_dag(circ) dag_drawer(dag) ------------------ --------------------------------------------------------------------------- FileNotFoundError Traceback (most recent call last) File /usr/local/anaconda3/envs/qiskit-tutorials-requirements-dev-txt-test-1/lib/python3.9/site-packages/pydot.py:1923, in Dot.create(self, prog, format, encoding) 1922 try: -> 1923 stdout_data, stderr_data, process = call_graphviz( 1924 program=prog, 1925 arguments=arguments, 1926 working_dir=tmp_dir, 1927 ) 1928 except OSError as e: File /usr/local/anaconda3/envs/qiskit-tutorials-requirements-dev-txt-test-1/lib/python3.9/site-packages/pydot.py:132, in call_graphviz(program, arguments, working_dir, **kwargs) 130 program_with_args = [program, ] + arguments --> 132 process = subprocess.Popen( 133 program_with_args, 134 env=env, 135 cwd=working_dir, 136 shell=False, 137 stderr=subprocess.PIPE, 138 stdout=subprocess.PIPE, 139 **kwargs 140 ) 141 stdout_data, stderr_data = process.communicate() File /usr/local/anaconda3/envs/qiskit-tutorials-requirements-dev-txt-test-1/lib/python3.9/subprocess.py:951, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask) 948 self.stderr = io.TextIOWrapper(self.stderr, 949 encoding=encoding, errors=errors) --> 951 self._execute_child(args, executable, preexec_fn, close_fds, 952 pass_fds, cwd, env, 953 startupinfo, creationflags, shell, 954 p2cread, p2cwrite, 955 c2pread, c2pwrite, 956 errread, errwrite, 957 restore_signals, 958 gid, gids, uid, umask, 959 start_new_session) 960 except: 961 # Cleanup if the child failed starting. File /usr/local/anaconda3/envs/qiskit-tutorials-requirements-dev-txt-test-1/lib/python3.9/subprocess.py:1821, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, gid, gids, uid, umask, start_new_session) 1820 err_msg = os.strerror(errno_num) -> 1821 raise child_exception_type(errno_num, err_msg, err_filename) 1822 raise child_exception_type(err_msg) FileNotFoundError: [Errno 2] No such file or directory: 'dot' During handling of the above exception, another exception occurred: FileNotFoundError Traceback (most recent call last) Input In [17], in () 2 from qiskit.tools.visualization import dag_drawer 3 dag = circuit_to_dag(circ) ----> 4 dag_drawer(dag) File /usr/local/anaconda3/envs/qiskit-tutorials-requirements-dev-txt-test-1/lib/python3.9/site-packages/qiskit/utils/lazy_tester.py:165, in LazyDependencyManager.require_in_call..out(*args, **kwargs) 162 @functools.wraps(function) 163 def out(*args, **kwargs): 164 self.require_now(feature) --> 165 return function(*args, **kwargs) File /usr/local/anaconda3/envs/qiskit-tutorials-requirements-dev-txt-test-1/lib/python3.9/site-packages/qiskit/visualization/dag_visualization.py:247, in dag_drawer(dag, scale, filename, style) 245 with tempfile.TemporaryDirectory() as tmpdirname: 246 tmp_path = os.path.join(tmpdirname, "dag.png") --> 247 dot.write_png(tmp_path) 248 with Image.open(tmp_path) as test_image: 249 image = test_image.copy() File /usr/local/anaconda3/envs/qiskit-tutorials-requirements-dev-txt-test-1/lib/python3.9/site-packages/pydot.py:1743, in Dot.__init__..new_method(path, f, prog, encoding) 1739 def new_method( 1740 path, f=frmt, prog=self.prog, 1741 encoding=None): 1742 """Refer to docstring of method `write.`""" -> 1743 self.write( 1744 path, format=f, prog=prog, 1745 encoding=encoding) File /usr/local/anaconda3/envs/qiskit-tutorials-requirements-dev-txt-test-1/lib/python3.9/site-packages/pydot.py:1828, in Dot.write(self, path, prog, format, encoding) 1826 f.write(s) 1827 else: -> 1828 s = self.create(prog, format, encoding=encoding) 1829 with io.open(path, mode='wb') as f: 1830 f.write(s) File /usr/local/anaconda3/envs/qiskit-tutorials-requirements-dev-txt-test-1/lib/python3.9/site-packages/pydot.py:1933, in Dot.create(self, prog, format, encoding) 1930 args = list(e.args) 1931 args[1] = '"{prog}" not found in path.'.format( 1932 prog=prog) -> 1933 raise OSError(*args) 1934 else: 1935 raise FileNotFoundError: [Errno 2] "dot" not found in path. FileNotFoundError: [Errno 2] "dot" not found in path. ```

Steps to reproduce the problem

conda create --name qiskit-tutorials-dev
conda install pip
pip install -r requirements-dev.txt
conda install pandoc
sphinx-build -b html . _build/

my current requirements-dev.txt looks like this based on this https://github.com/Qiskit/qiskit-tutorials/issues/1317#issuecomment-1129818689:

qiskit
jupyter
sphinx
nbsphinx
sphinx_rtd_theme
networkx
scikit-learn
matplotlib
qiskit[visualization]
cvxpy
pyscf
graphviz

What is the expected behavior?

Building successfully without error

Suggested solutions

bopardikarsoham commented 2 years ago

This happens when we install pydot through pip install pydot and that too through graphviz instead we should install it through conda conda install pydot. This removes the dot error.

bopardikarsoham commented 2 years ago

pydot itself contains graphviz-2.38 so we can add pydot to requirements-dev.txt

mtreinish commented 2 years ago

You need to have graphviz installed, it's not a python dependency so you have to install it independently see: https://graphviz.org/download/ for instructions on how to do this

HuangJunye commented 2 years ago

I see! So this is similar to pandoc. I was confused by the documentation of the python interface package of the same name https://graphviz.readthedocs.io/en/stable/manual.html