Guidelines/System for pip packages installation

I don’t know if the question has already been discussed, I haven’t found anything on the forum, and it is has been on my mind for a few month now so I’m opening this thread.

Is there some guidelines for the installation of pip packages from addons ? If there is, maybe they should be put on the developper wiki and python API documentation.

From what I saw on various addons using pip packages, pip is called with a subprocess, using bpy.app.binary_path_python. While it works in most cases, I see the following issues with this approach:

  • the blender installation is modified without asking or at least notifying the user that something is going on.
  • on windows, if Blender is installed in Program Files and not run as administrator, this does not work and might show cryptic messages to the user, and only in the console
  • the blender installation might be shared on a network disk, if a user has an addon that install pip packages it will alter the installation for every one (this issue can be avoided by restricting write rights on the folder for users, but we fall back to the previous issue, the user will have cryptic failure messages)
  • as a developper knowing what pip packages an addon uses requires digging in the source code

So in my opinion it would be great if at least the BF would provide guidelines on how to install pip packages. I was thinking of things like:

  • provide a requirements.txt file in the addon folder to list pip dependencies explicitly
  • use “python -m pip install -r” on this file to install the packages, if it fails handle nicely the error to provide a good warning message to the user
  • disable the addon for the session if it cannot be registered because pip packages are missing and cannot be installed

An improvement to this idea would be to provide an api with blender to do all of this with a few call.

And the ultimate sugar would be to have such behavior directly handled by Blender, when an addon is registered. For such a system maybe requirements.txt is not the good place, and the list of packages to install may be put in bl_info dictionnary instead.

What do you think of these ideas ? If you notice I’m missing something important here please tell me.

8 Likes

I am a bit concerned here about the lack of reply. I myself don’t have any answers to your questions, but I find the observations very interesting, I had not considered that addons might need to use pip installed modules from pypi.

I have been working a lot on regressing addons, checking that they can run on multiple versions of blender, but also multiple OSs. I suspect that this is where using pip install modules might cause issues. If you use a module is is working on all OSs? It increases the surface areas of problems.

Part of my extended discussions elsewhere have highlighted that the addons support and maintenance in blender is a bit lacking. In addition to your points, the ability to update an addon natively through blender, error reporting if the addon crashes, some kind of pypi for addons, with compatibility rating. I have bought a few addons via blender market and gumroad. But when the addon is updated, I get a mail, then I have to log in and redownload and reinstall … this could be improved … a lot. Something like the way plugins are updated and update-able in WordPress is an example.

Don’t get me wrong, I think it is great and should be done, but if the framework is being opened there are a few other things that could be done.

I found this today, kinda answers your question

https://developer.blender.org/T71420

1 Like

virtualenv is the python way to “control” pip install. Blender should introduce support for virtualenv.

It’s not a trivial topic but a good design would bring “proper packaging” for addons and this would be a game changer !

Thanks for the link to this task (already saw it in the past actually, but I had forgotten :stuck_out_tongue:). I’ve added my proposition in the comments.

1 Like