注意一下如果你使用的是Python3,pip改成pip3
根据下面的内容我们可以发现:
sudo apt-get install xsel xclip
Introduction
Purpose
The purpose of Pyperclip is to provide a cross-platform Python module for copying and pasting text to the clipboard.
To copy text to the clipboard, pass a string to pyperclip.copy()
. To paste the text from the clipboard, call pyperclip.paste()
and the text will be returned as a string value.
>>> import pyperclip
>>> pyperclip.copy('Hello world!')
>>> pyperclip.paste()
'Hello world!'
Not Implemented Error
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.pip install gtk
to install the gtk Python module.pip install PyQt4
to install the PyQt4 Python module.
Example Usage
>>> import pyperclip
>>> pyperclip.copy('The text to be copied to the clipboard.')
>>> pyperclip.paste()
'The text to be copied to the clipboard.'
Currently only handles plaintext.
On Windows, no additional modules are needed.
On Mac, this module makes use of the pbcopy and pbpaste commands, which should come with the os.
On Linux, this module makes use of the xclip or xsel commands, which should come with the os. Otherwise run "sudo apt-get install xclip" or "sudo apt-get install xsel" (Note: xsel does not always seem to work.)
Otherwise on Linux, you will need the gtk or PyQt4 modules installed.