Hello. I’d just like to import numpy package into my plugin. But when I add “import numpy” to the py file, the plugin doesn’t work. Also, I read the article below.
Did you installed pip on your Python3 installation? Yes
Did you made a copy/paste of site-package directory (from Python3 installation) to krita’s python directory? Yes. ‘C:\Users\myName\AppData\Local\Programs\Python\Python39\Lib\site-packages’ directory to ‘C:\Program Files\Krita (x64)\python’ directory
and Krita’s scripter returned like:
==== Warning: Script not saved! ====
Try to load PIL
Failed No module named ‘PIL’
Try to load numpy
Failed No module named ‘numpy’
ImportError: No module named pip
In file: runpy.py
In function: _get_module_details at line: 137. Line with error:
Now what you need is to install the lacking modules. In this case Pillow and numpy.
I know, Krita asked for PIL not Pillow. It just that Pillow is the ‘continuation’ of PIL, so it still is used from within Python as PIL.
For this you will use the terminal. Just to be safe here a minimal step-by-step How to:
On the start menu open cmd or PowerShell
On the open terminal type: pip install Pillow wait for to install
Type pip install numpy
Done. You should now have both numpy and PIL installed
For what I see:
‘C:\Users\myName\AppData\Local\Programs\Python\Python39\Lib\site-packages’
You’ve installed Python 3.9
But Krita 5.1.3 use Python 3.8.1
There’s maybe a problem here, because Krita is not able to import pip module ImportError: No module named pip
Try to install Python 3.8
Please take care, Krita 5.2 will use Python 3.10
@Daishishi no, provided script execute PIP to install PIL and numpy modules automatically; problem here is the pip module is not recognized by Krita so it’s not possible to install anything
Also executing pip outside Krita won’t do anything as Krita load its own python environment; pip modules installation must be made within Krita with functions provided in my script
Seems it’s not working from scripter a then should activate and execute PIP through a plugin executed at startup
Unfortunately, it seems the plugin I’ve written when I tested pip install on windows is not on my windows anymore, not sure I still have old virtual-disk of my previous windows VM installation…
I’m so confused. I always though that every python3 instance shared the same pip installation folder.
In the case of my Linux machine: /usr/lib/python3 So every subsequent python installation would reference this folder.
Maybe isn’t like this for krita because it is inside its own environment?
Inside Krita using the scripter I looked where krita’s Python is located
import os
print(os.path)
I got: tmp/.mount_krita-pp1i19/usr/lib/python3.8
@Grum999 Can’t you install the packages with pip inside this folder?
It means that additional work is required to be able to use PIP within krita
I currently don’t have the time to check that and rewrite plugin example for windows
You’re using an appimage
So no
As appimage recreate systematically all krita sandbox at startup; if you close Krita you’ll see, the folder doesn’t exist anymore
Also, here problem is relative to windows
If you go in this topic:
You’ll see that for Linux appimage it’s simpler and it’s explained where pip modules are installed
You might want to tell this to my Pop! OS 22.04 then
Here is what I got for running your initial code from the topic above:
==== Warning: Script not saved! ====
-------------------------------------------------------------------------
Try to load PIL
Failed No module named 'PIL'
Try to load numpy
Ok!
**********************
ImportError: No module named pip
In file: /tmp/.mount_krita-pp1i19/usr/lib/python3.8/runpy.py
In function: _get_module_details at line: 137. Line with error:
raise error("No module named %s" % mod_name)
**********************
Also this is wayyyyy above my head and I would only be guttering this topic with my unrelated remarks. So I will excuse myself and whish you good luck @drive.programming0 and @Grum999.
P.S.: Weirdly enough if I simply do: import numpy on my Krita 5.1.3 it just works, this is why I initially assumed the pip installation were shared.
If you’re using Krita installed from OS package, it’s different, it normally use python from system; but take care about incompatibilities…
It’s provided on PopOS! through a flatpak?
To import package you have to create a plugin that will load PIP and then install modules.
Plugin have to be executed at startup…
It’s not “difficult” to do everything but it take some time and need some development skills
If you’re a total beginner it will probably be a pain and you should try to understand how to code a plugin and how plugins works in krita before trying to use external libraries…