-1
$\begingroup$

When I run the following command

qc.draw(output='mpl')

for my circuit qc, I get this error:

ImportError: The class MatplotlibDrawer needs pylatexenc

How do I address this issue? Below an image of my problem

enter image description here

Update ------
Installation steps on Google Colaboratoy:
!pip install pylatexenc ?.

The installation attempt (was successful and the installed pylatexenc has version 2.7.)

$\endgroup$
  • 2
    $\begingroup$ Have you tried installing pylatexenc with whichever package manager you are using? $\endgroup$ – Rammus Sep 13 at 11:21
  • 1
    $\begingroup$ Thanks for the image. You have the latest version of Qiskit. $\endgroup$ – user9318 Sep 16 at 11:57
  • 1
    $\begingroup$ +1 vey good! The fact that you are using "google colab" is very important to know. I've never used it before. I'll get back to you as soon as I find more information. $\endgroup$ – user9318 Sep 16 at 12:09
  • 1
    $\begingroup$ Meanwhile, I think it would be a good idea if you post your question on stackoverflow and tag google-colaboratoy. $\endgroup$ – user9318 Sep 16 at 12:19
  • 1
    $\begingroup$ Check out this stackoverflow.com/questions/51342408/…. Also when you run the line !pip install pylatexenc in your notebook what is the output? Does it run without problem? $\endgroup$ – user9318 Sep 16 at 12:27
2
$\begingroup$

It's an issue with latest Qiskit I've noticed. Use following command to downgrade it to previous version(0.16.1 specifically) for the time being.

!pip install qiskit==0.16.1

| improve this answer | |
$\endgroup$
  • $\begingroup$ yes It is working on v0.16.1 but problem is with v0.21.0 I think this problem is happning on notebooks but not on IDLE or pycharm @dushyanth $\endgroup$ – quantum_boy Sep 18 at 10:37
1
$\begingroup$

The 0.15.2 is actually the version of your qiskit-terra package not Qiskit itself.
I'd suggest you to check the version by qiskit.__qiskit_version__. See the documentation.

If all packages have the latest version, you simply need to install pylatexenc in the same env where your Qiskit has been installed. Just by typing pip install pylatexenc in terminal!

In case you don't have the latest version of Qiskit. You need to upgrade it first by pip install qiskit --upgrade and then install pylatexenc.

Update
For Google Colab, this thread from Stackoverflow might be relevant.
%pip install pylatexenc

| improve this answer | |
$\endgroup$
  • $\begingroup$ Yes I have done exactly the same but still showing same error. please see my question again this time I also have provided the Image. @user9318 $\endgroup$ – quantum_boy Sep 16 at 11:58
  • $\begingroup$ I appreciate your effort you did for this problem brother but it is still not working. And I am taking your advise to post it on Stackoverflow. Thaknyou @user9318 $\endgroup$ – quantum_boy Sep 16 at 14:24
  • $\begingroup$ @quantum_boy did you find a way around that? $\endgroup$ – dushyanth Sep 17 at 14:36
  • $\begingroup$ No, Do you have solution?@dushyanth $\endgroup$ – quantum_boy Sep 17 at 14:38
  • 1
    $\begingroup$ I just found solution read my answer and thanks for you effort and time @user9318 $\endgroup$ – quantum_boy Sep 17 at 23:56
1
$\begingroup$

use %matplotlin inline before executing draw('mpl') here is the link for more info

| improve this answer | |
$\endgroup$
  • $\begingroup$ Line magic function %matplotlin not found. It shows this $\endgroup$ – dushyanth Sep 18 at 10:40
  • $\begingroup$ @dushyanth, There is a type it should be %matplotlib inline. $\endgroup$ – user9318 Sep 18 at 13:49
  • $\begingroup$ %matplotlib inline even this doesn't fix it. I get the same error mentioned in the question ImportError: The class MatplotlibDrawer needs pylatexenc. $\endgroup$ – dushyanth Sep 19 at 4:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.