Search code examples
pythonpiprobotframeworkrpa

Including Images in a library with pip install


I'm working on building a python 3.8 based automation library and parts of the library require .PNG files to locate items on the screen.

Is there a way to do this or is this outside the realm of how pip was meant to function?

I've tried pip installing from a git repo as well as from a local directory. The .PNG files are never copied.

I tried putting a __ init __ py in the folder containing the images, which makes it create the folder the images are in, but still no images copied.

I've googled the problem but all I've learned is there are pip libraries for PNG, images and extensions.


Solution

  • theres lots of ways to do it ...

    one way is to make use of include_package_data in your setup.py

    from setuptools import setup, find_packages
    setup(
        ...
        include_package_data=True
    )
    

    and include the datafiles in manifest.in

    or be more specific

    from setuptools import setup, find_packages
    setup(
        ...
        package_data={
            # If any package contains *.txt or *.rst files, include them:
            "": ["*.txt", "*.rst"],
            # And include any *.msg files found in the "hello" package, too:
            "hello": ["*.msg"],
        }
    )
    

    (see also: pypi setuptools documentation)

    another option is to store them as base64 encoded strings in a python file))

    images.py

    img1 = "<SOMEB64ENCODED_STR>"
    

    most packages allow you to specify images either as raw bytes or as base64encoded data