Search code examples
pythonimagepyperclip

Copying Image Using Python Pyperclip


I referred to an older post that used 'win32clipboard' to accomplish this task. However, when I tried installing it with pip install win32clipboard I encountered the following error:

'ERROR: Could not find a version that satisfies the requirement win32clipboard (from versions: none). ERROR: No matching distribution found for win32clipboard.

I'm asking this because I think win32clipboard is not available to me.

from PIL import Image
import pyperclip

# Open the image file
image_path = 'img.png'
image = Image.open(image_path)

# Copy to the clipboard
pyperclip.copy(image)

I am encountering an error while using the Pyperclip library in my Python script. When attempting to copy a file to the clipboard, I receive the following exception:
pyperclip.PyperclipException: only str, int, float, and bool values can be copied to the clipboard, not PngImageFile

I understand that Pyperclip only supports copying string, integer, float, and boolean values to the clipboard. However, in my case, I need to copy a .png file on clipboard.


Solution

  • Fixed it by installing win32clipboard! pip install pywin32