2
$\begingroup$

I'm on a Linux Ubuntu 18.04.1 LTS System.

As the title states I was unable to find any precise documentation how to build blender as Python Module for uses in scripts.

If anyone can help me I'd really appreciate it.

Thanks in advance.

$\endgroup$
  • $\begingroup$ Please see the answer i allready provided myself. There i explain why i "reasked/reformulated" the question. $\endgroup$ – Chgad Dec 24 '18 at 20:05
  • $\begingroup$ I too build blender on ubuntu 18. Building against python 3.71 which is also my system python, keeping (3.66) as system python3. If another python version is installed via apt, recommend removing the line in site.py that adds ../python3/site-packages to sys.path. I mention this since ubuntu is notoriously conservative in upgrading repos, and while 18 is new and 3.66 is good enough, blender will step to 3.7 or 3.8 well before. On dupe: Hunted down the dupe link just as you asked the question, became sidetracked and posted well after you answered. $\endgroup$ – batFINGER Dec 25 '18 at 2:55
  • $\begingroup$ On close as dupe: IMO It's a toss up, could add a ubuntu 18 specific answer there too. It really doesn't matter if it is voted to close. UV for make bpy I basically stick to configure, make, [sudo] make install. cmake-gui is my configure tool of choice pre building a blender target $\endgroup$ – batFINGER Dec 25 '18 at 3:07
  • $\begingroup$ On close as dupe: from a quick look, I believe your answer posted here should be an answer to the original question. That question doesn't have an accepted answer so a fresh new answer can still reach the top if it's good. If I'm wrong and the two questions are about two distinct needs then please make it clear in the text of the question what is this question about and why it's not the same. Also, the title should reflect this distinctness. I'm abstaining my close vote meanwhile. $\endgroup$ – Nicola Sap Dec 27 '18 at 8:24
  • $\begingroup$ I actually didn't look carefully for an Accepted Answer which, as you mentioned, the other Question DOESN'T have. I will copy my Answer with some specifications like "Ubuntu 18.04 specifc". $\endgroup$ – Chgad Dec 27 '18 at 20:41
2
$\begingroup$

Ok, i managed to actually build it as a Python module. It might appear strange to ask a question and immediately answer it. But i decided to share my experience with this process.

In this way it could help someone in the future who struggled the same way as i did.

Now to the process of the solution.

Starting point were the following three sources as follows :

  1. This Question

  2. An Archived Blender Wiki entry

  3. The offical "Build from source" Wiki article

How did i achieve the build ?

I started by following the description provided of the 2. Source; which wasn't really precise in how to handle the source and so on and did not work for me in the end.

After a few failures of this, i went on by just following the 3. Source.

So i did what was stated there :

mkdir ~/blender-git
cd ~/blender-git
git clone https://git.blender.org/blender.git
cd blender
git submodule update --init --recursive
git submodule foreach git checkout master
git submodule foreach git pull --rebase origin master

Afterwards :

cd ~/blender-git
./blender/build_files/build_environment/install_deps.sh

Now I had every bit of blender code and all dependencies installed. Since i did not want blender compiled with UI (as normal programm) i was curious what (described in the next step, step 3, in Source 3.) make in ~/blender-git/blender offered. So i proceeded with simply calling make help which gave the following (truncated for brevity) output :

Convenience targets provided for building blender, (multiple at once can be used)
* debug     - build a debug binary
* full      - enable all supported dependencies & options
* lite      - disable non essential features for a smaller binary and faster build
* headless  - build without an interface (renderfarm or server automation)
* cycles    - build Cycles standalone only, without Blender
* bpy       - build as a python module which can be loaded from python directly
* deps      - build library dependencies (intended only for platform maintainers)

* config    - run cmake configuration tool to set build options

Note, passing the argument 'BUILD_DIR=path' when calling make will override the
default build dir.
Note, passing the argument 'BUILD_CMAKE_ARGS=args' lets you add cmake arguments.

"Oh Hey, look what we got!" There it was, a make bpy which promised to solve all my problems.

So i executed it and it compiled. But I ended up with the Python module in a, at least for my desires, wrong directory : /usr/local/PYTHON_SITE_PACKAGES-NOTFOUND. I wondered how this happend.

I soon figured out that I had to reconfigure cmake in the new created ~/blender-git/linux_build_bpy via ccmake linux_build_bpy while in ~/blender-git. There i needed to enable the Advanced Settings via pressing t and then editing the Key PYTHON_SITE_PACKAGES from PYTHON_SITE_PACKAGES-NOTFOUND to my desired Path /usr/lib/python3.6/site-packages.

After changing this i had to rebuild the project, which didn't actually rebuild since the changed setting didn't affect the main build process.

Rebuild in ~/blender-git/blender via make bpy.

In the End I also deleted the stuff in /usr/local/PYTHON_SITE_PACKAGES-NOTFOUND. (Ofc i could've just moved/copied it...)

That's how it worked form me. I hope this is helpful in any kind for anyone in the future.

NOTES:

  1. make bpy might need superuser-rights so do a sudo make bpy and don't worry about a complete rebuild (it's allready done just linking/copying in the end needs those rights).

  2. The configuration after the first build might not be needed or can be done before hand, but i didn't figure out how to do so.

  3. If followed through these steps, and the Python module (strangely a directory called 2.80 or simmilar number) exists in the desired path but yet you are not able to import the module bpy in any of your scripts, make sure that your desired path is included in your PYTHONPATH Env-variable.

| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.