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.