无法让 pyperclip 在 python3 上使用复制和粘贴模块 [英] Cant get pyperclip to use copy and paste modules on python3

查看:44
本文介绍了无法让 pyperclip 在 python3 上使用复制和粘贴模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

规格:

  • Python3.5
  • 最新的 Pyperclip
  • 安装了 xclip 和 python3-pyqt4
  • 使用最新的 Raspian Stretch Light 使用 ssh(Putty) 连接到无头树莓派 2 型号 B
<小时>

错误:pyperclip.copy('Hello world!')文件/usr/local/lib/python3.5/dist-packages/pyperclip/__init__.py",第612行,在lazy_load_stub_copy返回副本(文本)文件/usr/local/lib/python3.5/dist-packages/pyperclip/__init__.py",第 297 行,在 __call__引发 PyperclipException(EXCEPT_MSG)pyperclip.PyperclipException:Pyperclip 无法为您的系统找到复制/粘贴机制.更多信息请访问 https://pyperclip.readthedocs.io/en/latest/introduction.html#not-implemented-error

我还尝试卸载并重新安装模块和剪贴板程序.我搜索了 2 个小时寻找答案并使用了所有这些,但它们没有用.我承认我是个菜鸟,但对我来说做这件事不应该这么难.

解决方案

剪贴板是 GUI 的一部分.但是您没有 GUI.所以没有剪贴板可以复制和粘贴.pyperclip 没有可访问的剪贴板,因此无论您如何尝试访问它,都将失败.

您可以通过在 shell 中运行它来轻松测试:

xclip

如果它显示类似 Error: No display: (null) 的内容,那是你的问题.

<小时>

如果你认为你应该有一个 GUI,因为你已经设置了一些东西,例如,通过 ssh 将 X11 隧道连接到台式机上的 X 服务器,但你仍然得到一个xclip 中的错误,那么问题是您设置错误.最简单的检查是:

echo $DISPLAY

那是空的吗?那么您的会话对您的 X11 隧道一无所知.正确设置隧道对于超级用户或 Unix 这样的网站来说确实是一个问题,而不是 Stack Overflow——一旦你解决了这个问题,pyperclip 和你的脚本就应该开始工作了.><小时>

至于你能做些什么……好吧,这取决于你最初尝试使用 pyperclip 的原因.在无头系统上,没有地方可以复制数据,也没有地方可以粘贴数据,所以它不会特别有用.

如果您尝试在同一台机器上的两个不同 Python 脚本之间共享数据,那么有比通过剪贴板传递数据更简单的方法——只需使用文件、管道、套接字、等等——甚至不需要设置复杂的第三方库.

Specs:

  • Python3.5
  • Latest Pyperclip
  • Both xclip and python3-pyqt4 installed
  • using ssh(Putty) to connect to headleass raspberry pi 2 model B using Latest Raspian Stretch Light

Error: pyperclip.copy('Hello world!')
  File "/usr/local/lib/python3.5/dist-packages/pyperclip/__init__.py", line 612, in lazy_load_stub_copy
    return copy(text)
  File "/usr/local/lib/python3.5/dist-packages/pyperclip/__init__.py", line 297, in __call__
    raise PyperclipException(EXCEPT_MSG)
pyperclip.PyperclipException:
    Pyperclip could not find a copy/paste mechanism for your system.
    For more information, please visit https://pyperclip.readthedocs.io/en/latest/introduction.html#not-implemented-error

I have also tried uninstalling and reinstalling both the module and clipboard programs. ive searched for 2 hours looking for an answer and used all of them and they didn't work. I admit i am a noob but it SHOULD'NT be this hard for me to do this.

解决方案

The clipboard is part of your GUI. But you don't have a GUI. So there is no clipboard to copy and paste with. There is no clipboard for pyperclip to access, so it doesn't matter how you try to access it, you're going to fail.

You can test very easily by running this at the shell:

xclip

If it says something like Error: No display: (null), then that's your problem.


If you think you should have a GUI, because you've set things up to, e.g., tunnel X11 through ssh to an X server on your desktop machine, but you're still getting an error from xclip, then the problem is that you've set things up wrong. The simplest thing to check is:

echo $DISPLAY

Is that empty? Then your session doesn't know anything about your X11 tunnel. Getting tunneling set up properly is really an issue for a site like Super User or Unix, not Stack Overflow—and, once you get that fixed, pyperclip, and your script, should just start working.


As for what you can do about it… well, it depends on why you were trying to use pyperclip in the first place. On a headless system, there's nowhere to copy data from, and nowhere to paste it to, so it wouldn't be particularly useful.

If you're trying to, e.g., share data between two different Python scripts on the same machine, then there are simpler ways to do that than passing it through a clipboard—just use a file, a pipe, a socket, etc.—that don't even require a third-party library with complicated setup.

这篇关于无法让 pyperclip 在 python3 上使用复制和粘贴模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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