Cant get pyperclip to use copy and paste modules on python3
Question:
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.
Answers:
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.
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.
sudo apt-get install xclip
Run this command on your terminal, then run the Python test.
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.
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
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.
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.
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.
sudo apt-get install xclip
Run this command on your terminal, then run the Python test.
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.
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