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

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

问题描述

规格:

  • Python3.5
  • 最新的Pyperclip
  • 同时安装了xclip和python3-pyqt4
  • 使用ssh(Putty)使用最新的Raspian Stretch Light连接到headleass树莓派pi 2模型B

 错误:pyperclip.copy('Hello world!')lazy_load_stub_copy中的第612行的文件"/usr/local/lib/python3.5/dist-packages/pyperclip/__init__.py"返回副本(文本)__call__中的第297行的文件"/usr/local/lib/python3.5/dist-packages/pyperclip/__init__.py"引发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这样的站点而言,正确设置隧道确实是一个问题,而不是堆栈溢出-并且,一旦修复了该问题, 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天全站免登陆