10

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.

Matthew Mankiewicz
  • 113
  • 1
  • 1
  • 8
  • Have you set things up to, e.g., tunnel X11 through ssh to an X server on your desktop? – abarnert Aug 02 '18 at 21:18
  • Also, what are you trying to _do_ with the clipboard? On a headless system, there's nothing to copy from or paste into. – abarnert Aug 02 '18 at 21:20

5 Answers5

13

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.

abarnert
  • 354,177
  • 51
  • 601
  • 671
  • 1
    its the very latest version of the light os when i echo display it gives me a blank line, but im currently download the latest full os for raspian and will get back to you when i test it. also i dont expect there to be a gui cause inever set one up . – Matthew Mankiewicz Aug 02 '18 at 21:46
  • @MatthewMankiewicz I don't know what the first half of that is about or why it's relevant. But if you don't have a GUI, then what are you expecting to do with the clipboard? As-is, what you're asking to do just doesn't make sense. But I'm sure you're trying to do something that makes perfect sense, and if you can explain what it is, we can probably tell you a way to accomplish it. – abarnert Aug 02 '18 at 21:49
  • im just using the raspberry pi as a python programming enviroment. i was gonna use pyperclip to copy the msg hello world then use pyperclip to paste it into the cmd line – Matthew Mankiewicz Aug 02 '18 at 22:14
  • @MatthewMankiewicz What you paste into the command line with Cttl-V or whatever doesn’t come from the rpi’s clipboard, it comes from your Windows clipboard through Putty. There’s no way code running on the rpi can affect that. – abarnert Aug 02 '18 at 22:19
  • i mean i want to use pyperclip.copy("Hello World") within the pi and paste it in the pi. Because the pi is supposed to copy the msg that its set to copy and paste it into the cmd line. BUt ive already established that the missing gui is probably the issue here. thanks for your responses though! – Matthew Mankiewicz Aug 02 '18 at 22:25
  • also i just conencted the pi to a moniter and did it manually and it stil lsays same error – Matthew Mankiewicz Aug 02 '18 at 22:48
  • @MatthewMankiewicz When you connected it to a monitor, are you running a text framebuffer, or are you running an X11 GUI? – abarnert Aug 02 '18 at 22:50
11
sudo apt-get install xclip

Run this command on your terminal, then run the Python test.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
hussein
  • 111
  • 1
  • 3
2

The issue is solved by installing one of the recommended utility, read the Pyperclip’s documentation. So, depending on your system, it could be: sudo apt-get install xclip

storenth
  • 967
  • 11
  • 18
0

I seem to remember having the same problem on my first Raspberry Pi. Try running sudo apt-get install xsel. You can read about what this does here, but essentially it's a clipboard utility that Pyperclip can use.

If this doesn't work it probably has something to do with the fact that you're trying to do this over SSH, but that shouldn't necessarily be an issue.

Ben Botvinick
  • 2,837
  • 3
  • 16
  • 41
-1

You may get an error message that says: “Pyperclip could not find a copy/paste mechanism for your system. Please see https://pyperclip.readthedocs.io/en/latest/introduction.html#not-implemented-error for how to fix this.”

In order to work equally well on Windows, Mac, and Linux, Pyperclip uses various mechanisms to do this. Currently, this error should only appear on Linux (not Windows or Mac). You can fix this by installing one of the copy/paste mechanisms:

  • sudo apt-get install xsel to install the xsel utility.
  • sudo apt-get install xclip to install the xclip utility.
Cyclic3
  • 149
  • 2
  • 10