Pyperclip 出现错误 [英] Pyperclip is giving an error

查看:111
本文介绍了Pyperclip 出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 python 2.7.我使用 sudo pip install pyperclip 安装了 pyperclip,并且安装成功.

每次使用下面的简单代码

导入pyperclippyperclip.copy('Hello World')消息=pyperclip.paste()打印(消息)

我收到以下错误:

/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:57:GtkWarning:无法打开显示警告.warn(str(e),_gtk.Warning)/usr/local/lib/python2.7/dist-packages/pyperclip/__init__.py:102:GtkWarning: IA__gtk_clipboard_get_for_display: 断言 'display !=NULL' 失败 cb = gtk.Clipboard() 回溯(最近一次调用): 中的文件first.py",第 401 行pyperclip.copy('Hello World') 文件/usr/local/lib/python2.7/dist-packages/pyperclip/__init__.py",行102,在_copyGtkcb = gtk.Clipboard() 运行时错误:无法创建 GtkClipboard 对象

解决方案

阅读文档总是有帮助的.

<块引用>

在 Windows 上,不需要额外的模块.在 Mac 上,该模块使用 pbcopy 和 pbpaste,它们应该与 os.在 Linux 上,通过包管理器安装 xclip 或 xsel.例如,在 Debian 中:须藤 apt-get 安装 xclip

否则在 Linux 上,您将需要安装 gtk 或 PyQt4 模块.

gtk 和 PyQt4 模块不适用于 Python 3,并且这个模块还不能与 PyGObject 一起工作.

我可以从您的帖子中看到您使用的是基于 Unix 的操作系统.所以你需要在你的终端上做的就是 sudo apt install xclip 然后通过 pip 安装 gtk 和 PyQt4 模块(因为你使用的是 python 2).

I use python 2.7. I installed pyperclip using sudo pip install pyperclip and it was installed successfully.

Every time I use the following simple code

import pyperclip
pyperclip.copy('Hello World')
message=pyperclip.paste()
print (message)

I get the following error:

/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:57:
GtkWarning: could not open display   warnings.warn(str(e),
_gtk.Warning) /usr/local/lib/python2.7/dist-packages/pyperclip/__init__.py:102:
GtkWarning: IA__gtk_clipboard_get_for_display: assertion 'display !=
NULL' failed   cb = gtk.Clipboard() Traceback (most recent call last):
File "first.py", line 401, in <module>
    pyperclip.copy('Hello World')   File "/usr/local/lib/python2.7/dist-packages/pyperclip/__init__.py", line
102, in _copyGtk
    cb = gtk.Clipboard() RuntimeError: could not create GtkClipboard object

解决方案

It always helps to read the documentation.

On Windows, no additional modules are needed.
On Mac, the module uses pbcopy and pbpaste, which should come with the os.
On Linux, install xclip or xsel via package manager. For example, in Debian:
sudo apt-get install xclip

Otherwise on Linux, you will need the gtk or PyQt4 modules installed.

gtk and PyQt4 modules are not available for Python 3, and this module does not work with PyGObject yet.

I can see that you're using a unix based operating system from your post. So all you need to do at your terminal is sudo apt install xclip and then the gtk and PyQt4 modules via pip(since you use python 2).

这篇关于Pyperclip 出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆