I
I
Ilya Korol2020-05-14 13:37:28
Python
Ilya Korol, 2020-05-14 13:37:28

How to add an image to a pip package?

The task was to automate the generation of a QR code with a unique style.
In the middle of the QR code, the organization's logo should be full of colors (this is a png image).
We need to create a module for PyPi, which, when installed via pip, will generate a QR code with the style
Module wrote, but images are not loaded into the package.
How to make the logo image upload for the module to work?

How I did:

from PIL import Image
from io import BytesIO
import requests
byteImgIO = BytesIO(requests.get("correct_url").content)
byteImgIO.seek(0)
logo1 = Image.open(byteImgIO)

I get the error
UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x0000027DAF0F6BF8>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Karbivnichy, 2020-05-14
@welcome32

You must specify the full and working address of the image. For example,
in a browser it might look like this:
site.ru/image/1.png
but the full path to the image is:
site.ru/upload/bbb66f0a05a24e79a1284abbb8358426.png
Your code works, but if you specify the wrong path, you will get the same error.
5ebd36cde4d98842846034.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question