小编Don*_*agh的帖子

Pyserial:无法配置端口:(5,'输入/输出错误)

我一直试图在过去的两天里运行以下两行Python代码,但没有取得多大成功:

import serial
ser = serial.Serial(0)
Run Code Online (Sandbox Code Playgroud)

每次运行它,我都会收到以下错误:

Traceback (most recent call last):
  File "./test.py", line 4, in <module>
    ser = serial.Serial(0)
  File "/usr/lib/python2.7/dist-packages/serial/serialutil.py", line 260, in __init__
    self.open()
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 280, in open
    self._reconfigurePort()
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 308, in _reconfigurePort
    raise SerialException("Could not configure port: %s" % msg)
serial.serialutil.SerialException: Could not configure port: (5, 'Input/output error')
Run Code Online (Sandbox Code Playgroud)

我正在运行Ubuntu 11.10 64位,Pyserial 2.5(python-serial 2.5-2.1)和Python 2.7(python 2.7.2-7ubuntu2),我的用户是拨出组的成员.

我也在运行Ubuntu 11.10 64位,使用相同版本的Python和Pyserial,并且似乎没有出现问题.欢迎任何建议 - 我很沮丧......

谢谢,多纳

python linux ubuntu pyserial

5
推荐指数
1
解决办法
1万
查看次数

迫使matplotlib图的背景是透明的

我正在尝试在我正在编写的Python Gtk3应用程序中包含一个matplotlib图.我想将图形的背景颜色设置为透明,这样图形就会显示出应用程序的自然灰色背景,但到目前为止我所尝试的内容似乎都没有效果.

这是一个MWE:

from gi.repository import Gtk
import matplotlib.pyplot as plt
import matplotlib.lines as mlines
import numpy as np
from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg as FigureCanvas

class MyWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        fig, ax = plt.subplots()
        #fig.patch.set_alpha(0.0)
        x,y = np.array([[0, 1], [0, 0]])
        line = mlines.Line2D(x, y, c='#729fcf')
        ax.add_line(line)
        plt.axis('equal')
        plt.axis('off')

        fig.tight_layout()

        sw = Gtk.ScrolledWindow()
        sw.set_border_width(50)
        canvas = FigureCanvas(fig)
        sw.add_with_viewport(canvas)

        layout = Gtk.Grid()
        layout.add(sw)

        self.add(layout)

win = MyWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
Run Code Online (Sandbox Code Playgroud)

如果fig.patch.set_alpha(0.0)取消注释该行,则背景颜色只会变为白色而不是灰色.所有建议非常感谢!

python gtk pygtk matplotlib gtk3

5
推荐指数
1
解决办法
6550
查看次数

标签 统计

python ×2

gtk ×1

gtk3 ×1

linux ×1

matplotlib ×1

pygtk ×1

pyserial ×1

ubuntu ×1