0

我想使用“pyperclip”从剪贴板中获取文本,并使用“playsound”来播放预先制作的声音。

我制作了一个使用 playsound 的 Python 程序:效果很好。我用 pyperclip 制作了另一个:效果很好!

现在,当我导入两个库并使用 pyperclip 函数(此处粘贴)时,整个过程都会关闭,并且出现以下错误:

Traceback (most recent call last):
  File "clipboardToSound.py", line 3, in <module>
    text = pyperclip.paste()
  File "/home/marc/.local/lib/python3.8/site-packages/pyperclip/__init__.py", line 681, in lazy_load_stub_paste
    return paste()
  File "/home/marc/.local/lib/python3.8/site-packages/pyperclip/__init__.py", line 163, in paste_gtk
    clipboardContents = gtk.Clipboard().wait_for_text()
  File "/usr/lib/python3/dist-packages/gi/__init__.py", line 72, in __getattr__
    raise AttributeError(_static_binding_error)
AttributeError: When using gi.repository you must not import static modules like "gobject". Please change all occurrences of "import gobject" to "from gi.repository import GObject". See: https://bugzilla.gnome.org/show_bug.cgi?id=709183

我的代码是这样的:

from playsound import playsound
import pyperclip

text = pyperclip.paste()
print("Hello world")

如果您取出 playsound 导入,一切正常!

我在 Ubuntu 20.04 上。

4

0 回答 0