在安装pip的库中包含映像



我正在构建一个基于python 3.8的自动化库,该库的部分内容需要.PNG文件才能在屏幕上定位项目。

有没有办法做到这一点,或者这超出了pip的功能范围?

我尝试过从git repo和本地目录安装pip。.PNG文件永远不会被复制。

我尝试在包含图像的文件夹中放入一个__init__py,这使它创建了图像所在的文件夹,但仍然没有复制图像。

我在谷歌上搜索过这个问题,但我所学到的只是有用于PNG、图像和扩展的pip库。

有很多方法可以做到这一点。。。

一种方法是在你的设置中使用include_package_data。py

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

并将数据文件包含在manifest.in

或者是更具体的

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"],
}
)

(另请参阅:pypi setuptools文档(

另一种选择是将它们作为base64编码的字符串存储在python文件中(

images.py

img1 = "<SOMEB64ENCODED_STR>"

大多数包允许您将图像指定为原始字节或base64编码数据

最新更新