Coding for Qiskit
I watched this video: https://www.youtube.com/watch?v=RrUTwq5jKM4
Using Mac OS Big Sur Using Jupyter 2.0.8 Using Python 3.8
The below code did not work and therefore installed pylatexenc ('pip install pylatexenc') It installed successfully. I then restarted jupyter and It still prints the same error. When I try to reinstall pylatexenc - it says it already there. I tried running while Jupyter is on and in a new terminal (Mac) window I tried to reinstall it- get the same message. Tried 'import pylatexenc *' at beginning of code - does not work - any advice
Code:
from qiskit import *
from pylatexenc import *
qr = QuantumRegister(2)
cr = ClassicalRegister(2)
circuit = QuantumCircuit(qr, cr)
%matplotlib inline
circuit.draw()
circuit.h(qr[0])
circuit.draw(output='mpl')
Here is the error message:
ImportError Traceback (most recent call last)
<ipython-input-8-bd220039ee1c> in <module>
----> 1 circuit.draw(output='mpl')
~/opt/anaconda3/lib/python3.8/site-packages/qiskit/circuit/quantumcircuit.py in draw(self, output, scale, filename, style, interactive, plot_barriers, reverse_bits, justify, vertical_compression, idle_wires, with_layout, fold, ax, initial_state, cregbundle)
1496 from qiskit.visualization import circuit_drawer
1497
-> 1498 return circuit_drawer(self, scale=scale,
1499 filename=filename, style=style,
1500 output=output,
~/opt/anaconda3/lib/python3.8/site-packages/qiskit/visualization/circuit_visualization.py in circuit_drawer(circuit, scale, filename, style, output, interactive, plot_barriers, reverse_bits, justify, vertical_compression, idle_wires, with_layout, fold, ax, initial_state, cregbundle)
221 cregbundle=cregbundle)
222 elif output == 'mpl':
--> 223 image = _matplotlib_circuit_drawer(circuit, scale=scale,
224 filename=filename, style=style,
225 plot_barriers=plot_barriers,
~/opt/anaconda3/lib/python3.8/site-packages/qiskit/visualization/circuit_visualization.py in _matplotlib_circuit_drawer(circuit, scale, filename, style, plot_barriers, reverse_bits, justify, idle_wires, with_layout, fold, ax, initial_state, cregbundle)
515
516 global_phase = circuit.global_phase if hasattr(circuit, 'global_phase') else None
--> 517 qcd = _matplotlib.MatplotlibDrawer(qubits, clbits, ops, scale=scale, style=style,
518 plot_barriers=plot_barriers, layout=layout,
519 fold=fold, ax=ax, initial_state=initial_state,
~/opt/anaconda3/lib/python3.8/site-packages/qiskit/visualization/matplotlib.py in __init__(self, qubits, clbits, ops, scale, style, plot_barriers, layout, fold, ax, initial_state, cregbundle, global_phase, qregs, cregs)
126 self.plt_mod = plt
127 if not HAS_PYLATEX:
--> 128 raise ImportError('The class MatplotlibDrawer needs pylatexenc. '
129 'to install, run "pip install pylatexenc".')
130 self._clbit = []
import qiskit.tools.jupyter
and then run%qiskit_version_table
. Also, does the drawing work when you just do thiscircuit.draw()
? Could you restart your notebook and run it without this linefrom pylatexenc import *
and tell me what it did? And last, do you have matplotlib installed? You can check if it is by running this line on your notebook!pip list
. $\endgroup$