Pip would indeed be nice
pip is not included in the appimage with the current version (5.2.6); therefore the solution provided in the original post fails with an error.
However, I had more success installing the packages (or, indeed, pip itself) from a terminal provided I used the right version of Python and the right location.
Packages can be installed (almost painlessly, or perhaps a little painfully) as follows:
- Install pyenv - follow their instructions.
- Check the version and path of Python used by Krita via Scripter with:
The comments are snippets of the output from my Ubuntu MATE machine with Krita 5.2.6 appimage.import sys print(sys.version) # 3.10.7 (main, Sep 25 2024, 09:46:00) [GCC 11.4.0] print(sys.path) # [ '/tmp/.mount_krita-p9vswE/usr/lib/krita-python-libs/krita', # '/home/username/.local/share/krita/pykrita' ... ]
- Open a terminal select the version using pyenv:
pyenv install 3.10 pyenv shell 3.10
- Install the package to one of the (user) folders in
sys.path
, e.g.pip install numpy --target=/home/username/.local/share/krita/pykrita`
From Scripter, I can then import no problem:
import numpy
print(numpy.__file__)
# /home/username/.local/share/krita/pykrita/numpy/__init__.py
It’s plausible that a similar approach will work on Windows - the main hassle will be getting used to pyenv.
Bonus: You can also install pip to the same location as demonstrated for numpy above, and then similarly to the original post (but with less pretty wrapping) I can run the following in Scripter to install pillow:
import sys
import runpy
def exitFct(exitCode):
return exitCode
sys_exit_old = sys.exit
sys_argv_old = sys.argv
sys.exit = exitFct
try:
sys.argv.append('install')
sys.argv.append('pillow')
sys.argv.append('--target=/home/username/.local/share/krita/pykrita')
runpy.run_module('pip', run_name='__main__')
except Exception as e:
print(f'{e}')
sys.exit = sys_exit_old
sys.argv = sys_argv_old
I get a tonne of errors related to logging, but it succeeds.
I managed to achieve fully automatic requirements installations on both windows and linux (hopefully even macos, but I don’t have any mac system to try it out), your method was actually only missing a small but quite easy bit: you can actually download a pip
wheel from pypi at runtime and run pip straight from inside the wheel using runpy
!
this is my take at the thing: sonicvisions/modules.py · main · Marco Melletti / Sonic Visions · GitLab
in the plugin __init__.py
main code I try importing the plugin main class and on import errors I run the function downloading the external modules and suggest a restart (since Krita’s interpreter has already started and won’t find newly installed modules, I guess there is a workaround even for this issue but it seemed way less important than the installation itself to me)
the only installation method that is currently not working is linux from repository because it will use system-wide python installation directories where pip cannot write if run from regular user, but all “official” Krita installs work: linux appimage, flatpak, snap, windows install and windows portable