Pip4Blender

Overview

This is a Blender Add-on which enables support for using pip (the standard Python Package Manager) from within Blender.

Blender utilizes a bundled Python implementation, which does not include pip. Because of this, it is actually quite difficult to install third-party libraries and packages into the Blender Python Implementation.

This issue makes developing Blender Add-ons far more difficult, because developers cannot use tried-and-true 3rd party libraries, and are forced to write the same code over and over for each add-on that needs it.

Pip4Blender makes this just as easy as installing normal add-ons, and supports a developer-centric workflow designed to make building and distributing add-ons with dependencies as simple as possible.

Features

  • Install Pip into the Blender Python installation from the Blender UI
  • Use pip to install specific libraries from the Blender UI
  • Import requirements.txt files from the Blender UI
  • Generate requirements.txt files from the Blender UI
  • Compatible with all Blender versions using Python3 (ie. since Blender 2.5)
  • Compatible with all major Operating Systems (Windows, Mac, Linux)

License

PyAesel is licensed under the MIT license. For further details, please refer to the LICENSE file.

Contact

If you believe that you have found a bug in Pip4Blender, or have an enhancement request, we encourage you to raise an issue on our github page.

Installation

Pip4Blender is installed exactly like any other Blender add-on, and is distributed as a single Python file. The latest release can be downloaded from https://github.com/AO-StreetArt/pip4blender/releases.

Note

Users with Blender 2.80 should download the pip4blender.py file from the blender-2.80 branch. A new release compatible with Blender 2.80 will be created when the new version of Blender is officially released.

Add-on Install

From the User Preferences panel, select ‘Install Addon from File’, and select the pip4blender.py file.

_images/Install.png

Pip Install

Installing Pip in the Blender environment is also required before the rest of the functionality of the add-on is accessed. This can be done by selecting the ‘Install Pip in Blender’ button, but only needs to be done once for any given Blender installation.

This might take a few minutes to run, if you want to watch the installation progress you should run Blender from a terminal.

_images/Install_Pip.png

Getting Started

Now that the add-on is installed, we can use it to install any Python package available over pip.

Installing a Library with Pip

Installing a single package is done by specifying the package name, then using the ‘Install Python Library’ button:

_images/Install_Library.png

For example, if we type ‘requests’ into the text box shown above, then hit the button, we would install the Requests module into Blender’s Python installation with pip.

Installing a Requirements File with Pip

If you have been provided with a requirements.txt file, often along with an add-on you wish to install, you can hit the ‘Install Requirements File’ button, and select the file in the browser that opens up:

_images/Install_ReqFile.png

This will install all dependent packages specified in the requirements file to your Blender installation.

Developing with Pip4Blender

Developers creating new Add-ons will benefit the most from pip4blender. During initial development, developers can install libraries as needed, one-by-one. This reduces the overall cost of development by promoting use of solid, well-tested, third-party libraries instead of the same code re-written over and over again.

_images/Install_Library.png

Upgrading a Library

Upgrading a library can be accomplished by pre-pending ‘–upgrade’ to the name of the library. For example, to upgrade the requests library, we would enter ‘–upgrade requests’ into the ‘Package Name’ text field, then hit ‘Install Python Library’.

Be warned: DO NOT upgrade a package that came with Blender by default.

Distribution

Once an add-on is complete (enough) to release to the public, a requirements.txt file can be generated, which specifies the name and version of all dependent packages. This file can then be packaged along with an add-on, and distributed.

_images/Generate_ReqFile.png

User Installation

Users who have pip4blender installed can hit the ‘Install Requirements File’ button, which will open a file browser to select the requirements file supplied by the developer.

_images/Install_ReqFile.png

Known Limitations

There are several known limitations to consider when using pip4blender.

Updating Bundled Libraries

Pip4Blender should not be used to update libraries that came bundled with Blender. This has the potential to permanently damage your Blender installation.

Installing C Modules

C Modules which include the ‘Python.h’ header will fail. The bundled Python installation does not include the source files for Python, making this rather difficult. Support for this is not planned at this time.