Tag: blender

I constantly fiddle with a lot of Python scripts to automate or conduct experiments for my Geometry Processing endeavors using Blender. Usually, these scripts begin as a standalone and soon evolves as a fully functional addon. For the purpose of writing scripts in an efficient manner, I use Eclipse along with PyDev plugin. Once I have reached a certain stage of my addon development it becomes important to install and test the addon script often. In such a scenario the conventional route is to copy the addon folder with the python code to the Blender’s add-on directory. This proved to be a cumbersome process all the while and wasn’t a lot of fun, to begin with. But hey I use PyDev and Eclipse know well that a Python interpreter is available for it to use and run scripts from Eclipse.

The external tools configuration of Eclipse IDE. We can exploit this functionality to make our add-on development testing more easier.

In Eclipse IDE it is possible to create External tools configuration to run custom tasks and automate various process. With the python interpreter available it is possible to run a python script in the add-on directory that will copy itself to the Blender’s add-on folder to be installed as a plugin.

Firstly, we will look into the python script that can take care of installing (or copy) the add-on folder and its contents to the Blender add-on directory. Actually, the code is pretty much simple in its underlying logic. It reads the arguments supplied when running the script and then uses that information to install the plugin. The idea is to zip the contents of the folder and unzip it to the Blender’s add-on location.

${string_prompt:Version Text:2.79} – Which version of Blender are we targetting? Well, one can supply the full and final path to the Blender add-on location as the previous argument (argument 4). However, in my case, I test my addons with many versions of Blender. So this will help in that case

${string_prompt:Binary Text:blender} – The path to the Blender binary or executable. If supplied the addon will be installed and Blender will be called as a subprocess. It is a sheer matter of convenience. If left blank only the addon will be installed without invoking Blender.

Well, that’s it. I make it a point to copy this script to every Blender-addon project I have on Eclipse. Also by supply the arguments one can also run this script from the command line and achieve the same goal without using Eclipse. I have given the downloadables for everyone to use. Feel free to experiment and explore.

On any operating system, I want to recommend download of standalone Blender instead of using the installer. The installer tries to copy the executable and necessary libraries at locations that need super privileges to make any changes. These situations can be avoided if you are running from a stand-alone Blender instance.

One hiccup when using a standalone Blender is that the bundled python usually lacks “setuptools” and “distutils for some standard package installations. While there are many ways to solve this problem

On windows use Conda environment for Blender

Ubuntu and Mac, install the python interpreter Blender needs

or empower Blender’s bundled python

What I will discuss here is the 3rd option of empowering the Blender’s bundled python by adding distutils and setuptools. This way you don’t have to worry about downloading the huge anaconda setup for windows or go through a possible headache of compiling python from source for other systems. On Ubuntu you have the deadsnakes ppa but again this comes only with the dev packages and the interpreter itself. For the pip tools you have to manually do the get-pip.py step to install the required empowering tools. Rather this same idea of get-pip.py can be used to fix the bundled python of Blender.

First of all download the zipped or tarball of standalone Blender and unzip it to the location of your choice. Once you have downloaded and extracted it a location you should find the Blender folder with the much needed files and sub-folders inside it. Let us by an example to understand this better. If the choice is download version 2.79 then you shall find the embedded python at blenderlocation/2.79/python. Navigating to this directory will show you the below directories

Blender’s embedded python directory contents

bin – location that contains the embedded python interpreter

include – contains the include files for cythonic and other purposes

lib – the meaty part containing all the python packages

Fire up a terminal or command line utility and navigate to locationblenderlocation/2.79/python/bin. Inside this folder you should see files as shown in the below screenshot,

The python interpreter shipped with the downloaded standalone Blender.

Run the command as shown in the below screenshot

Ensure you have curl installed and available. Then run curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

Once you have finished getting the get-pip.py then proceed to executing the get-pip.py using the python executable inside the bin folder as shown in the below screenshot

Executing get-pip.py using the embedded python interpreter to install distutils and setuptools.

Step by step

Once the get-pip.py has finished executing then the bin folder will be populated with executables of pip, easy_install etc.,

Executables related to distutils and setuptools. In third row, the first three entries are the executables of pip.

Now that we have installed the setuptools and distutils it is time to test its ability to install third-party packages. The below screenshot shows an example of installing scikit-learn using the pip tool we just arranged.

The pip installs the packages to the lib folder of the embedded python interpreterThe scikit-learn is now available for your downloaded standalone Blender

Shall we call it a day? or has the day just begun with the tools in place now?

Recently I upgraded my Ubuntu 16.04 to 18.04. I should admit it was a charm to update without any fuss or muss. However, there was one peculiar problem, it was about setting up the python plugins that I wrote/writing for my ongoing Ph.D. research projects. Everything was working fine until reinstalling Blender 2.79 and using the good old python plugins of my research.

My research is oriented towards geometry-processing and there is no other suitable candidate other than Blender, which caters to my itchy research needs. Blender supports a beautiful rendering system using cycles and can also allow one to write python code such that its prowess can be extended with only creativity as the limits. As said earlier my research is towards geometry-processing and demands a lot from linear algebra packages such as numpy, and scipy. Also, scikit-learn is an important package that I am dealing with lately. It was while trying to use scikit-learn I bumped into issues. The weird issue was when using the below statement from the Blender console,from sklearn import preprocessing

Boom, I see another window with an error in the terminal, which says

from multiprocessing.semaphore_tracker import main;main(43)

After pulling out my hair over a few weeks I stumbled upon this link where this problem was being discussed. Following the read-up on this link lead me to this link. There the user mentions that the whole issue is a bug from multiprocessing python library.

The text from the last link states,

When SemaphoreTracker.ensure_running() from blender-2.79b-linux-glibc219-x86_64/2.79/python/lib/python3.5/multiprocessing/semaphore_tracker.py is executed it runs another Blender instance with arguments -c from multiprocessing.semaphore_tracker import main;main(9) by mistake.

It all became as clear as a day. A line (#55) in semaphore_tracker.py it tries to keep the python instance alive when importingsklearn. As we are running python as an instance inside the Blender software, the lineexe=spawn.get_executable() will return the path of the blender executable instead of the python interpreter inside Blender. Obviously, Blender is not a python instance. To fix this we have to manually point the variable to an actual python interpreter path used for Blender. This depends if you are using the system python or the bundled python. I would recommend that it is better to download and use the standalone Blender version instead of installable. Again the whole game behind this logic changes if you are a windows user. In this writing context, it is Ubuntu, so I chose to download the standalone version of Blender 2.79 and used the bundled python. So opening the file at /home/myusername/blender-2.79/2.79/python/lib/python3.5/multiprocessing/semaphore_tracker.py and changing the line #55 in that python file toexe = /home/myusername/blender-2.79/2.79/python/bin/python
solve the problem. As such I am not sure how good is this fix, however, it serves the purpose for now.