Want to share experience (for the sake of google search) of the using python libs inside Krita with scripting (in addon/scripter/etc). There is several threads on this, but no definitive cross-platform solution - since pip is not present on some platforms (MacOs, Windows) and copying packages into Krita have problems on platforms with appimage.
So there is a description of another approach, not mentioned before - start Krita from bash script. Probably especially helpful for addon developers. Script deletes developing addon folder and replaces it with fresh copy and then getting site-package folder path of local python 3.9 installation and save it into text file inside krita addons folder. then addon read it on initialization and adding to sys.path - and all locally installed packages became visible inside Krita without additional efforts
from bash script:
PATH_KRITAEXE_MAC="/Applications/krita510.app/Contents/MacOS/krita" # Your path here
# python must be set to proper version!
# Krita 5.1.5 == Python 3.9
# conda activate py39
# python -m pip install Pillow
# python -m pip install numpy
# python -m pip install scipy
# python -m pip install scikit-image
module_path=`python -m pip show pip | grep 'Location:'`
module_path="${module_path:10}"
if [[ -z "$module_path" ]]; then
echo "- python: no pip/etc installation found"
exit 0
fi
echo "$module_path" > "$PATH_PYKRITA/wplstudio/python_site_packages.txt"
"$PATH_KRITAEXE_MAC"
from addon initialization:
info_file = os.path.join(os.path.dirname(__file__), 'python_site_packages.txt')
try:
# reading site-packages file, if any
python_site_packages = open(info_file).read()
python_site_packages = python_site_packages.strip()
print("- site-packages:", python_site_packages)
sys.path.insert(0,python_site_packages)
except Exception as e:
print("- site-packages: no data", info_file, e)
this is for savy users, of course, but would like to know possible drawbacks