Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
705 views
in Technique[技术] by (71.8m points)

python - Cant get pyperclip to use copy and paste modules on python3

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...