How to import python package?

Hello,

Please, I’m kinda stupid, I can’t figure this out and I’d really appreciate an advice.

I’d like to import a pip installed package. Currently I have a virtual environment (venv) set up in a separate directory, I’d like to grab/copy/anything possible/… a package installed through pip install package_name but I have no idea how to do this so it’s available in my krita plugin, please?

I’d be nice if I could distribute the plugin with the package without the user needing to install it on their own.

Well I have no idea if it’s even possible.

Thank you very much.

1 Like

Hi

This may help you

Grum999

1 Like

Hm, that does seem overlycomplicated and expects a user to be able to install python that sounds unfortunately prohibiting.

Thanks a lot anyway :slight_smile: it’s helpful to see this.

EDIT:
@Grum999 I asked in the chat, it seems missing pip on windows is not a Krita problem but just a way how it works on windows, apparently if you know how to inject it into krita installation you can let people know, they might not be against it, which sounds to me like it’s probably a huge pain if it’s even remotely possible xD.

I asked why pip was not embedded with windows, and this was the answer:

Then if someone is able to embed it for windows maybe it will be easier.
Just need to find a developer with a windows computer and able to do it :slight_smile:

And should also be provided for macOS in this case I suppose.

Grum999

Hehe, then I have no idea. :slight_smile:

EDIT:
@Grum999
This is the whole answer I got from amyspark:
I think it's fully "you're on your own" territory, at least where Windows is concerned (because embedded Python doesn't ship an interpreter)... but i think so, yes. if you find a way to inject pip into the installation^^

Hi! I found a less “overlycomplicated” method

Copy your installed plugin folder from:

“C:\Users\Username\AppData\Local\Programs\Python\Python13\Lib\site-packages”

to:

“C:\Program Files\Krita (x64)\lib\site-packages”

I mean, if a user can install a plugin, they should be able to do this as well, right?

To summarize:

  1. Open cmd.exe.

  2. Run pip install (if Python is installed). If it’s not, install it first
    (use the same python version as krita!!!)
    Use Tools → Scripter
    and ctrl+v this

import sys
print(sys.version)

to detect version

  1. Copy the plugin folder into Krita’s plugin folder.

And with the next update, everything is gone … :see_no_evil_monkey:

It has more than one reason why users should NOT do anything in the directory where Krita is installed, for instance the thing I wrote above, also it is the main reason for users having issues with Krita.
There is nothing complicated with a longer path to a well known location.
“Hints” like yours make supporting users who have problems with Krita not only more difficult, but also more likely and more frequent. Because which supporter suspects that users are messing around in directories they have no business in, no, such “hints” will also increase the number of those who will have problems with Krita, because the number of those who, out of incompetence, will ruin their Krita in this way will increase, only the proven solutions are not applicable to such capital user errors.
Thank you!

I can only strongly advise against implementing such tips yourself, at least if you are not in a position to rectify the damage yourself. And that is probably over 95% of those users who would never have thought of this themselves.

Michelist

Sorry for the late reply, but yeah - you’re right
No need to do that
I don’t know why I answered like that - maybe I didn’t read the question carefully and thought it was about Scripter

Answering the first question:

If you’re making a PLUGIN, to import your own libraries, you need to write a proper init.py

1 Like