3dmess
3dmess

Reputation: 13

How to install bpy module Python Linux?

I have a CentOS7 Linux setup with a conda environment and Python version 3.10.

I am attempting to download bpy version 3.6.0 module into my python environment but am getting errored out with this message.

ERROR: Ignored the following versions that require a different python version: 2.82.1 
Requires-Python >=3.7, <3.8 ERROR: Could not find a version that satisfies the requirement bpy==3.6.0 (from versions: 3.4.0) 
ERROR: No matching distribution found for bpy==3.6.0

I don't understand this error and online searches don't really help. Do I need blender installed separately? I do have a blender installation but it is for blender 3.3, it is exported to the PATH as well.

Does anyone have any idea on how to download bpy as a module?

I need version 3.6.0 to run code that works with that version. I am constrained and cannot downgrade.

I simply tried pip install and it did not work.

I searched online for this and nothing related to this issue appeared. Although I admit I could not much understand the Requirements section of the bpy 3.6.0 installation.

Thanks!

Upvotes: 1

Views: 2998

Answers (1)

jsbueno
jsbueno

Reputation: 110476

BPY can only work from inside Blender itself - the Blender binary app launches a Python interpreter inside its process, and the core of BPY is then able to manipulate internal Blender data structures and call various API procedures.

This means bpy cannot be imported in a standalone Python interpreter - only from a Python interpreter started within Blender itself (which happens automatically when Blender runs)

That said, there is a way to start a headless (no window) Blender process, that will run a Python script directly, and be able to access the Blender API trough the bpy module. The shell command line will be blender --background --python myscript.py, and not python myscript.py (Blender CLI options seem here).

In other words: calling blender in this qay initializes Blender and all the data structures needed by the BPY module, and Blender starts a Python interpreter with the bpy module available.

Installing 3rd party Python modules in the Python interpreter used inside Blender is possible, and have to be done with some care.

some Linux distributions that package Blender will use the system Python for blender as well, and any Python package installed via the distriution package manager will be usable inside a script run inside blender (i.e. if you use dnf install python3-requests in a RedHat system rather than pip install requests ).

Otherwise, blender binaries downloaded from Blender.org will carry their own Python environments with thn, so if your blender is expaned under a directory called blender-3.6.0-linux-x64, for example (or whatever directory name you got when unzipping), you can run the "pip" utility which comes along with it by typing, for example blender-3.6.0-linux-x64/3.6/python/bin/python3.11 -m pip. This pip can install Python packages inside the Blender local install that will be available for your script. (Note that the numbers 3.6 and 3.11 above are the versions for Blender and Python respectively, and might change - so your blender might be with python3.10 or python3.12 - just check whatever file is present in the [install]/3.6/python/bin folder)

update At the end of the Blender page linked above, it is mentioned that Blender itself can be built as a Python module - and then bpy would work running straight from the Python interpreter. But you have to build Blender yourself following the instructions there.

Upvotes: 1

Related Questions