Cant Get Pyperclip To Use Copy And Paste Modules On Python3
Solution 1:
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.
Solution 2:
sudo apt-get install xclip
Run this command on your terminal, then run the Python test.
Solution 3:
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.
Solution 4:
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.
Post a Comment for "Cant Get Pyperclip To Use Copy And Paste Modules On Python3"