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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…