blenderproc.python.utility.SetupUtility module

Ensures that all necessary pip packages are installed in the blender environment.

class blenderproc.python.utility.SetupUtility.SetupUtility[source]

Bases: object

Setup class, ensures that all necessary pip packages are there

static _ensure_pip(python_bin, packages_path, packages_import_path, pre_python_package_path, force_update=False)[source]

Make sure pip is installed and read in the already installed packages

Parameters:
  • python_bin (str) – Path to python binary.

  • packages_path (str) – Path where our pip packages should be installed

  • packages_import_path (str) – Path to site-packages in packages_path which contains the installed packages

  • pre_python_package_path (str) – Path that contains blender’s default pip packages

  • force_update (bool) – If True, the installed-packages-cache will be ignored and will be recollected based on the actually installed packages.

static _pip_install_packages(required_packages, python_bin, packages_path, reinstall_packages=False, dry_run=False, use_custom_package_path=True)[source]

Installs the list of given pip packages in the given python environment.

Parameters:
  • required_packages – A list of pip packages that should be installed. The version number can be specified via the usual == notation.

  • python_bin – Path to python binary.

  • packages_path – Path where our pip packages should be installed

  • reinstall_packages (bool) – Set to true, if all python packages should be reinstalled.

  • dry_run (bool) – If true, nothing will be installed, and it will only be checked whether there are any potential packages to update/install.

  • use_custom_package_path (bool) – If True, the python packages are installed into a custom folder, separate from blenders own python packages.

Return type:

bool

Returns:

Returns True, if any packages were update/installed or - if dry_run=True - if there are any potential packages to update/install.

static check_if_setup_utilities_are_at_the_top(path_to_run_file)[source]

Checks if the given python scripts has at the top an import to SetupUtility, if not an exception is thrown. With an explanation that each python script has to start with SetupUtility.

Parameters:

path_to_run_file (str) – path to the used python script

static clean_installed_packages_cache(blender_path, major_version)[source]

Removes the json file containing a list of all installed pip packages (if it exists).

Parameters:
  • blender_path – The path to the blender main folder.

  • major_version – The major version string of the blender installation.

static determine_python_paths(blender_path, major_version)[source]

Determines python binary, custom pip packages and the blender pip packages path.

Parameters:
  • blender_path (Optional[str]) – The path to the blender main folder.

  • major_version (Optional[str]) – The major version string of the blender installation.

Return type:

str

Returns:

  • The path to the python binary of the blender installation

  • The path to the directory containing custom pip packages installed by BlenderProc

  • The path to the directory containing pip packages installed by blender.

static determine_temp_dir(given_temp_dir)[source]

Finds and creates a temporary directory.

On linux the temp dir is per default placed in /dev/shm or /tmp. The name of the created temp dir contains a uuid, so multiple BlenderProc processes can run on one system.

Parameters:

given_temp_dir (str) – A directory inside which the temp dir should be created

Return type:

str

Returns:

The path to the created temp dir.

static extract_file(output_dir, file, mode='ZIP')[source]

Extract all members from the archive into output_dir.

Parameters:
  • output_dir (str) – The output directory that should contain the extracted files.

  • file (Union[str, BytesIO]) – The path to the archive which should be extracted.

  • mode (str) – The type of the given file, has to be in [“TAR”, “ZIP”]

static extract_from_response(output_dir, response)[source]

Extract all members from the archive to output_dir

Parameters:
  • output_dir (str) – the dir to zip file extract to

  • response (Response) – the response to a requested url that contains a zip file

installed_packages: Optional[Dict[str, str]] = {'autopep8': '1.6.0', 'bop-toolkit': None, 'certifi': '2021.10.8', 'charset-normalizer': '2.0.10', 'cython': '0.29.30', 'docutils': None, 'gitpython': '3.1.18', 'h5py': '3.6.0', 'human-body-prior': None, 'idna': '3.3', 'imageio': '2.9.0', 'm2r2': None, 'matplotlib': '3.5.1', 'numpy': '1.23.5', 'opencv-contrib-python': '4.5.5.64', 'packaging': None, 'pillow': '8.3.2', 'pip': '23.3.1', 'pycodestyle': '2.8.0', 'pygments': None, 'pyopengl': '3.1.0', 'pypng': '0.0.20', 'pyrender': '0.1.45', 'python-dateutil': '2.8.2', 'pytz': '2021.1', 'pyyaml': '5.1.2', 'requests': '2.27.1', 'rich': '12.6.0', 'scikit-image': '0.19.2', 'scikit-learn': '1.0.2', 'scipy': '1.11.3', 'setuptools': '65.5.0', 'smplx': None, 'sphinx': None, 'sphinx-autodoc-typehints': None, 'sphinx-rtd-theme': None, 'toml': '0.10.2', 'trimesh': '3.21.5', 'urdfpy.git': None, 'urllib3': '1.26.8', 'wheel': None, 'zstandard': '0.16.0'}
main_setup_called = True
package_list_is_from_cache = True
static setup(user_required_packages=None, blender_path=None, major_version=None, reinstall_packages=False, debug_args=None)[source]

Sets up the python environment.

  • Makes sure all required pip packages are installed

  • Prepares the given sys.argv

Parameters:
  • user_required_packages (Optional[List[str]]) – A list of python packages that are additionally necessary to execute the python script.

  • blender_path (Optional[str]) – The path to the blender installation. If None, it is determined automatically based on the current python env.

  • major_version (Optional[str]) – The version number of the blender installation. If None, it is determined automatically based on the current python env.

  • reinstall_packages (bool) – Set to true, if all python packages should be reinstalled.

  • debug_args (Optional[List[str]]) – Can be used to overwrite sys.argv in debug mode.

Return type:

List[str]

Returns:

List of sys.argv after removing blender specific commands

static setup_pip(user_required_packages=None, blender_path=None, major_version=None, reinstall_packages=False, use_custom_package_path=True, install_default_packages=True)[source]

Makes sure the given user required and the general required python packages are installed in the BlenderProc env

At the first run all installed packages are collected via pip freeze. If a pip packages is already installed, it is skipped.

Parameters:
  • user_required_packages (Optional[List[str]]) – A list of pip packages that should be installed. The version number can be specified via the usual == notation.

  • blender_path (Optional[str]) – The path to the blender installation.

  • major_version (Optional[str]) – The version number of the blender installation.

  • reinstall_packages (bool) – Set to true, if all python packages should be reinstalled.

  • use_custom_package_path (bool) – If True, the python packages are installed into a custom folder, separate from blenders own python packages.

  • install_default_packages (bool) – If True, general required python packages are made sure to be installed.

Return type:

str

Returns:

Returns the path to the directory which contains all custom installed pip packages.

static setup_utility_paths(temp_dir)[source]

Set utility paths: Temp dir and working dir.

Parameters:

temp_dir (str) – Path to temporary directory where Blender saves output. Default is shared memory.

static uninstall_pip_packages(package_names, blender_path, major_version)[source]

Uninstalls the given pip packages in blenders python environment.

Parameters:
  • package_names (List[str]) – A list of pip packages that should be uninstalled.

  • blender_path (str) – The path to the blender main folder.

  • major_version (str) – The major version string of the blender installation.