1

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

2 Answers2

5

After installing pip install pylatexenc

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

Nitin
  • 396
  • 7
  • 18
0

I'm new to this liveries, but I ran your code in Colab and it said I needed to install pylatexenc, so I did and got the following output.

MissingOptionalLibraryError: "The 'pylatexenc' library is required to use 'MatplotlibDrawer'. You can install it with 'pip install pylatexenc'."

enter image description here

r-beginners
  • 31,170
  • 3
  • 14
  • 32
  • I don't know anything about this genre, so I can't give you a detailed answer. If my answer is helpful to you, please click the check mark to accept the answer! – r-beginners Aug 27 '21 at 14:22
  • If you've already done this, it's beyond my scope. I checked further and found a similar issue reported on github. See here for [reference](https://github.com/Qiskit/qiskit-terra/issues/6094). – r-beginners Aug 28 '21 at 14:37
  • I know this won't help you, but I'll share the code I ran in the [Colab](https://colab.research.google.com/drive/17RSjDYrDHxAzbsQJehAuAz-1jS83PRYn?usp=sharing) environment. I will remove it if it is confirmed. – r-beginners Aug 28 '21 at 14:46