qiskit利用circuit.draw(output=‘mpl‘)报错

报错信息:

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

报错原因:

没有安装相关包,根据报错提示安装相关包即可:

C:\Users\dell>pip install pylatexenc

查看包的相关信息:

C:\Users\dell>pip show pylatexenc

输出信息: 

Name: pylatexenc
Version: 2.10
Summary: Simple LaTeX parser providing latex-to-unicode and unicode-to-latex conversion
Home-page: https://github.com/phfaist/pylatexenc
Author: Philippe Faist
Author-email: philippe.faist@bluewin.ch
License: MIT
Location: c:\users\dell\appdata\local\programs\python\python39\lib\site-packages
Requires:
Required-by:

我根据提示安装了相关的包还是一直提示:

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

简直要崩溃,后面我想到可能是因为我是开了另一个cmd,然后完成了相关包的安装工作,但是现在的代码所处环境还没加载到安装的包,于是我重新关掉jupyter notebook,重新进了一下jupyter notebook,成功!!!激动的我抓紧吃了个橙子,又是写bug的一天。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
这段代码是一个简单的绘图程序,使用鼠标左键点击画布可以绘制一条直线,右键可以更改颜色,中键可以删除上一条直线。同时,按下键盘上的 "c" 键可以清空画布。不过这段代码有一些错误,需要进行修正。下面是修正后的代码: ```python from itertools import cycle import matplotlib.pyplot as plt x = [] y = [] # 可用的颜色和当前颜色 colors = cycle('rgbcmyk') color = next(colors) def onMouseClick(event): global color if event.button == 1: # 单击鼠标左键,绘制新直线 x.append(event.xdata) y.append(event.ydata) if len(x) > 1: plt.plot([x[-2], x[-1]], [y[-2], y[-1]], c=color, lw=2) elif event.button == 3: color = next(colors) elif event.button == 2: if ax.lines: del ax.lines[-1] x.pop() y.pop() event.canvas.draw() def onClose(event): print('Closed') def onClear(event): if event.key == 'c': ax.lines.clear() x.clear() y.clear() event.canvas.draw() # 创建图形 fig = plt.figure() ax = plt.gca() plt.xticks(range(10)) plt.yticks(range(10)) fig.canvas.mpl_connect('button_press_event', onMouseClick) fig.canvas.mpl_connect('key_press_event', onClear) fig.canvas.mpl_connect('close_event', onClose) plt.show() ``` 主要的修改如下: 1. `onMonseclick` 改为 `onMouseClick`,修正了单词拼写错误; 2. 在 `onMouseClick` 函数中,增加了 `event.button == 2` 的判断,即中键的点击事件; 3. `onclose` 改为 `onClose`,修正了单词拼写错误; 4. `onclear` 改为 `onClear`,修正了单词拼写错误; 5. 在 `onClear` 函数中,增加了事件处理后的画布重绘操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值