Python Environment

It is possible to run Isaac Sim natively from python rather than as a standalone executable. This provides more low-level control over how to initialize, step and manage an omniverse application.

Setup

There are two possible ways to run your python scripts natively with omniverse:

Option 2: Running with Anaconda

First, navigate to the python_samples directory in the base of the package

cd python_samples

Can create a new environment with the following command:

conda env create -f environment.yml
conda activate isaac-sim

If you have an existing conda env, ensure that the packages in environment.yml are installed. Alternatively you can delete and re-create your conda environment using:

conda remove --name isaac-sim --all
conda env create -f environment.yml
conda activate isaac-sim

Finally, we need to setup some environment variables so that Isaac Sim python packages are located correctly. On Linux, you can do this with:

source setenv.sh

You can then run samples as follows in the isaac-sim conda env:

Note

If using the isaac-sim conda env you can use python instead of python.sh to run any of the samples

python path/to/script.py

OmniKitHelper

The OmniKitHelper Class provides convenience functions to manage the lifetime of a Omniverse Isaac Sim application.

Usage Example:

The following code provides a usage example for how the helper can be used to create an app, step forward in time and then exit.

Note

Any omniverse level imports must occur after the helper class is instantiated. Because APIs are provided by the extension/runtime plugin system, it must be loaded before they will be available to import.

Important

When running headless:

  • Set "headless": True in the config when initializing OmniKitHelper

  • Any calls that create/open a matplotlib window need to be commented out

import os
from omni.isaac.python_app import OmniKitHelper

CONFIG = {
    "experience": f'{os.environ["EXP_PATH"]}/omni.isaac.sim.python.kit',
    "renderer": "RayTracedLighting",
    "headless": True,
}

if __name__ == "__main__":
    # Simple example showing how to start and stop the helper
    kit = OmniKitHelper(config=CONFIG)

    ### Perform any omniverse imports here after the helper loads ###

    kit.play()  # Start simulation
    kit.update(1.0 / 60.0)  # Render a single frame
    kit.stop()  # Stop Simulation
    kit.shutdown()  # Cleanup application

Details: How OmniKitHelper works

The sample code shown below can be executed via:

./python.sh python_samples/core/app_framework.py

There are three steps to loading an omniverse application in python. The first is to get the carbonite framework:

import carb
self.framework = carb.get_framework()
self.framework.load_plugins(
        loaded_file_wildcards=["omni.kit.app.plugin"],
        search_paths=[os.path.abspath(f'{os.environ["CARB_APP_PATH"]}/plugins')],
    )

Here CARB_APP_PATH was previously defined by running using python.sh

We then set up the startup arguments for the application

# Inject experience config:
sys.argv.insert(1, f'{os.environ["EXP_PATH"]}/omni.isaac.sim.python.kit')

# Add paths to extensions
sys.argv.append(f"--ext-folder")
sys.argv.append(f'{os.path.abspath(os.environ["ISAAC_PATH"])}/exts')
# Run headless
sys.argv.append("--no-window")

# Set some settings
sys.argv.append("--/app/asyncRendering=False")

And then start the application

self.app.startup("Isaac-Sim", app_root, sys.argv)

Shutting down a running application is done by calling shutdown and then unloading the framework

self.app.shutdown()
self.framework.unload_all_plugins()