Search code examples
pythonlinuxclipboard

How to copy a file/image to the clipboard in Linux using Python


I can't find a way to copy an image or a file to the clipboard. I tried using pyperclip but it isn't able to do that.


Solution

  • I found a way to do this using a shell command:

    os.system(f"xclip -selection clipboard -t image/png -i {path + '/image.png'}")

    It's less than ideal but it does the job.