Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qiskit: mpl drawer module

I started using Qiskit with their official tutorial (Sezon 1) and I got a few bugs with the same code, at the beginning I just had to install pylatexenc but then I had "module 'qiskit.circuit' has no attribute 'draw'" error, this is not true as I used it before, I found some things about it on GitHub but no clear solution, my code is:

from qiskit import *
qr = QuantumRegister(2)
cr = ClassicalRegister(2)
circuit = QuantumCircuit(qr, cr)
circuit = QuantumCircuit(qr, cr)
circuit.draw()

[it worked, output:

      
q0_0: 
      
q0_1: 
      
c0: 2/
      ]

circuit.h(qr[0])
[output: <qiskit.circuit.instructionset.InstructionSet at 0x12dc159de50>]

circuit.draw(output= 'mpl')

error: 
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-4b6f233c71ed> in <module>
----> 1 circuit.draw(output= 'mpl')

AttributeError: module 'qiskit.circuit' has no attribute 'draw'

I use jupiter and Python 3.8, if version is wrong please tell me what version should I use and where do I download it, also, the output in first circuit.draw() is for some reason different than in original video


1 Answers

After installing pip install pylatexenc

you must restart your notebook kernel and run again. It worked for me!

like image 200
Nitin Avatar answered Sep 13 '25 14:09

Nitin