Skip to content

Instantly share code, notes, and snippets.

@plembo
Last active April 15, 2024 18:23
Show Gist options
  • Save plembo/6a035299f50db092ab710c74eaf6dcfb to your computer and use it in GitHub Desktop.
Save plembo/6a035299f50db092ab710c74eaf6dcfb to your computer and use it in GitHub Desktop.
Linux workaround for pyperclip.copy

Linux workaround for pyperclip.copy

Al Sweigart's pyperclip library for Python attempts to provide cross-platform methods for interacting with the clipboard on a computer desktop. I and others have found that the .copy method does not work with our Linux desktops (mine is currently Ubuntu 18.04 LTS with the default Gnome Shell).

A workaround was identified gkotian in an issue opened on the project's Github repo.

Here's the snippet provided by gkotian, which I used in a project from Al's Automate the Boring Stuff with Python book.:

import os

text = 'The text to be copied to the clipboard.'
os.system("echo '{}' | xclip -selection clipboard".format(text))

This workaround requires installation of astrand's xclip program (installed on Ubuntu with "sudo apt install xclip").

@plembo
Copy link
Author

plembo commented Apr 15, 2024

Sorry for the late reply. I really wouldn't know where to begin to answer you question. As this is merely a (very) low traffic gist archive, it's unlikely anyone else will even see it. I'd suggest going to https://github.com/asweigart/pyperclip/issues to see if anyone there can help. Also, it looks like pyperclip is no longer supported, so you might want to look for an alternative like this: https://github.com/NikitaBeloglazov/clipman.

@Lu251970
Copy link

Sorry for the late reply. I really wouldn't know where to begin to answer you question. As this is merely a (very) low traffic gist archive, it's unlikely anyone else will even see it. I'd suggest going to https://github.com/asweigart/pyperclip/issues to see if anyone there can help. Also, it looks like pyperclip is no longer supported, so you might want to look for an alternative like this: https://github.com/NikitaBeloglazov/clipman.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment