Error Installing pip Package for Python Extension

I am a relatively new Omniverse developer attempting to get an extension project set up for my team. My current project is primarily based off of kit-extension-template-cpp (using Kit 105.0.2 on Windows), and I’ve been able to successfully build and test the example extensions provided in that repo.

I’m now trying to create a custom Python-only extension able to install/use additional pip packages (specifically, SciPy 1.11.3), and have so far been mostly unsuccessful. When running kit.exe with my extension (dat.pypkg.test) enabled, I get the following output containing errors:

[680.759s] [ext: dat.pypkg.test-1.0.0] startup
calling pip install: c:\projects\s2somniverseextensions\_build\windows-x86_64\release\kit\python/python.exe -m pip --isolated install --target=C:\Users\Gavin\AppData\Local\ov\data\Kit\omni.app.kit.dev\1.0\pip3-envs\default scipy==1.11.3 --no-index --find-links=c:\projects\s2somniverseextensions\_build\windows-x86_64\release\exts\dat.pypkg.test\pip_prebundle
calling pip install: c:\projects\s2somniverseextensions\_build\windows-x86_64\release\kit\python/python.exe -m pip --isolated install --target=C:\Users\Gavin\AppData\Local\ov\data\Kit\omni.app.kit.dev\1.0\pip3-envs\default scipy==1.11.3 --no-index --find-links=c:\projects\s2somniverseextensions\_build\windows-x86_64\release\exts\dat.pypkg.test\pip_archive
calling pip install: c:\projects\s2somniverseextensions\_build\windows-x86_64\release\kit\python/python.exe -m pip --isolated install --target=C:\Users\Gavin\AppData\Local\ov\data\Kit\omni.app.kit.dev\1.0\pip3-envs\default scipy==1.11.3 --no-index --find-links=c:\projects\s2somniverseextensions\_build\windows-x86_64\release\kit\exts\omni.kit.pip_archive\pip_archive
calling pip install: c:\projects\s2somniverseextensions\_build\windows-x86_64\release\kit\python/python.exe -m pip --isolated install --target=C:\Users\Gavin\AppData\Local\ov\data\Kit\omni.app.kit.dev\1.0\pip3-envs\default scipy==1.11.3Collecting scipy==1.11.3
  Using cached scipy-1.11.3.tar.gz (56.3 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
    Preparing wheel metadata ... error
    ERROR: Command errored out with exit status 1:
     command: 'c:\projects\s2somniverseextensions\_build\windows-x86_64\release\kit\python\python.exe' 'C:\Users\Gavin\AppData\Local\ov\data\Kit\omni.app.kit.dev\1.0\pip3-envs\default\pip\_vendor\pep517\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\GAVINL~1\AppData\Local\Temp\tmpwbvof5zh'
         cwd: C:\Users\Gavin\AppData\Local\Temp\pip-install-ureup1jq\scipy
    Complete output (39 lines):
    + meson setup C:\Users\Gavin\AppData\Local\Temp\pip-install-ureup1jq\scipy C:\Users\Gavin\AppData\Local\Temp\pip-install-ureup1jq\scipy\.mesonpy-62j0_8ms -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --native-file=C:\Users\Gavin\AppData\Local\Temp\pip-install-ureup1jq\scipy\.mesonpy-62j0_8ms\meson-python-native-file.ini
    The Meson build system
    Version: 1.2.2
    Source dir: C:\Users\Gavin\AppData\Local\Temp\pip-install-ureup1jq\scipy
    Build dir: C:\Users\Gavin\AppData\Local\Temp\pip-install-ureup1jq\scipy\.mesonpy-62j0_8ms
    Build type: native build
    Project name: SciPy
    Project version: 1.11.3
    Activating VS 16.11.27
    C compiler for the host machine: cl (msvc 19.29.30151 "Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30151 for x64")
    C linker for the host machine: link link 14.29.30151.0
    C++ compiler for the host machine: cl (msvc 19.29.30151 "Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30151 for x64")
    C++ linker for the host machine: link link 14.29.30151.0
    Cython compiler for the host machine: cython (cython 0.29.36)
    Host machine cpu family: x86_64
    Host machine cpu: x86_64
    Program python found: YES (c:\projects\s2somniverseextensions\_build\windows-x86_64\release\kit\python\python.exe)
    Run-time dependency python found: YES 3.10
    Program cython found: YES (C:\Users\Gavin\AppData\Local\Temp\pip-build-env-1tjvw4yo\overlay\Scripts\cython.EXE)
    Compiler for C supports arguments -Wno-unused-but-set-variable: NO
    Compiler for C supports arguments -Wno-unused-function: NO
    Compiler for C supports arguments -Wno-conversion: NO
    Compiler for C supports arguments -Wno-misleading-indentation: NO
    Library m found: NO

    ..\meson.build:82:0: ERROR: Unknown compiler(s): [['ifort'], ['gfortran'], ['flang'], ['pgfortran'], ['g95']]
    The following exception(s) were encountered:
    Running `ifort --version` gave "[WinError 2] The system cannot find the file specified"
    Running `ifort -V` gave "[WinError 2] The system cannot find the file specified"
    Running `gfortran --version` gave "[WinError 2] The system cannot find the file specified"
    Running `gfortran -V` gave "[WinError 2] The system cannot find the file specified"
    Running `flang --version` gave "[WinError 2] The system cannot find the file specified"
    Running `flang -V` gave "[WinError 2] The system cannot find the file specified"
    Running `pgfortran --version` gave "[WinError 2] The system cannot find the file specified"
    Running `pgfortran -V` gave "[WinError 2] The system cannot find the file specified"
    Running `g95 --version` gave "[WinError 2] The system cannot find the file specified"
    Running `g95 -V` gave "[WinError 2] The system cannot find the file specified"

    A full log can be found at C:\Users\Gavin\AppData\Local\Temp\pip-install-ureup1jq\scipy\.mesonpy-62j0_8ms\meson-logs\meson-log.txt
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\projects\s2somniverseextensions\_build\windows-x86_64\release\kit\python\python.exe' 'C:\Users\Gavin\AppData\Local\ov\data\Kit\omni.app.kit.dev\1.0\pip3-envs\default\pip\_vendor\pep517\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\GAVINL~1\AppData\Local\Temp\tmpwbvof5zh' Check the logs for full command output.
WARNING: You are using pip version 20.1.1; however, version 23.2.1 is available.
You should consider upgrading via the 'c:\projects\s2somniverseextensions\_build\windows-x86_64\release\kit\python\python.exe -m pip install --upgrade pip' command.
2023-10-02 19:30:57 [911,187ms] [Warning] [omni.kit.pipapi.pipapi] 'scipy==1.11.3' failed to install.
2023-10-02 19:30:57 [911,190ms] [Error] [omni.ext._impl._internal] Failed to import python module dat.pypkg.test from c:\projects\s2somniverseextensions\_build\windows-x86_64\release\exts\dat.pypkg.test. Error: module 'scipy' has no attribute '__version__'. Traceback:
Traceback (most recent call last):
  File "c:\projects/s2somniverseextensions/_build/windows-x86_64/release/kit/kernel/py\omni\ext\_impl\_internal.py", line 186, in _custom_importer
    return _import_public(ext_module.path, ext_module.name, reload_enabled)
  File "c:\projects/s2somniverseextensions/_build/windows-x86_64/release/kit/kernel/py\carb\profiler\__init__.py", line 83, in wrapper
    r = f(*args, **kwds)
  File "c:\projects/s2somniverseextensions/_build/windows-x86_64/release/kit/kernel/py\omni\ext\_impl\_internal.py", line 93, in _import_public
    module = import_module(module_name)
  File "c:\projects/s2somniverseextensions/_build/windows-x86_64/release/kit/kernel/py\carb\profiler\__init__.py", line 83, in wrapper
    r = f(*args, **kwds)
  File "c:\projects/s2somniverseextensions/_build/windows-x86_64/release/kit/kernel/py\omni\ext\_impl\custom_importer.py", line 76, in import_module
    return importlib.import_module(name)
  File "c:\projects\s2somniverseextensions\_build\windows-x86_64\release\kit\python\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "c:/projects/s2somniverseextensions/_build/windows-x86_64/release/exts/dat.pypkg.test/dat/pypkg/test/__init__.py", line 1, in <module>
    from .extension import *
  File "c:/projects/s2somniverseextensions/_build/windows-x86_64/release/exts/dat.pypkg.test/dat/pypkg/test/extension.py", line 14, in <module>
    print(scipy.__version__)
AttributeError: module 'scipy' has no attribute '__version__'

2023-10-02 19:30:57 [911,190ms] [Error] [carb.scripting-python.plugin] Exception: Extension python module: 'dat.pypkg.test' in 'c:\projects\s2somniverseextensions\_build\windows-x86_64\release\exts\dat.pypkg.test' failed to load.

At:
  c:\projects/s2somniverseextensions/_build/windows-x86_64/release/kit/kernel/py\omni\ext\_impl\_internal.py(212): startup
  c:\projects/s2somniverseextensions/_build/windows-x86_64/release/kit/kernel/py\omni\ext\_impl\_internal.py(323): startup_extension
  PythonExtension.cpp::startup()(2): <module>

2023-10-02 19:30:57 [911,191ms] [Error] [omni.ext.plugin] [ext: dat.pypkg.test-1.0.0] Failed to startup python extension.
[911.505s] [ext: omni.app.kit.dev-1.0.0] startup

I have attempted to configure my extension to install SciPy at build time according to the Build-time installation using repo_build and omni.kit.pipapi docs. Here are some potentially relevant excerpts from my project files for additional context:

deps/pip.toml

[[dependency]]
packages = [
    "scipy==1.11.3",             # SWIPAT filed under: http://nvbugs/123456
]
target = "../_build/target-deps/pip_prebundle"

source/extensions/dat.pypkg.test/premake5.lua

-- Setup the extension.
local ext = get_current_extension_info()
project_ext(ext)

-- Link folders that should be packaged with the extension.
repo_build.prebuild_link {
    { "data", ext.target_dir.."/data" },
    { "docs", ext.target_dir.."/docs" },
    { "dat", ext.target_dir.."/dat" },
    { "%{root}/_build/target-deps/pip_prebundle", ext.target_dir.."/pip_prebundle" },
}

source/extensions/dat.pypkg.test/config/extension.toml

# Use omni.ui to build simple UI
[dependencies]
"omni.kit.uiapp" = {}
"omni.kit.pipapi" = {}

# Main python module this extension provides, it will be publicly available as "import dat.pypkg.test".
[[python.module]]
name = "dat.pypkg.test"

# Demonstrate how to add another folder to sys.path. Here we add pip packages installed at build time.
[[python.module]]
name = "scipy"
path = "pip_prebundle"

[python.pipapi]
# List of additional directories with pip achives to be passed into pip using ``--find-links`` arg.
# Relative paths are relative to extension root. Tokens can be used.
archiveDirs = ["pip_prebundle"]

# Commands passed to pip install before extension gets enabled. Can also contain flags, like `--upgrade`, `--no--index`, etc.
# Refer to: https://pip.pypa.io/en/stable/reference/requirements-file-format/
requirements = [
    "scipy==1.11.3"
]

modules = [
    "scipy"
]

# Allow going to online index. Required to be set to true for pip install call.
use_online_index = true

# Ignore import check for modules.
ignore_import_check = false

As a final caveat, I was actually able to use SciPy from a Python extension in Kit by doing python -m pip install scipy via a terminal directly inside C:\packman-repo\chk\kit-sdk\105.0.2+release.109459.e3a297f7.tc.windows-x86_64.release\python before running kit.exe, but I get the impression that installing modules this way is not a good idea.

Any info that could help me figure out what I’m missing here, temporary workarounds, or further troubleshooting steps would be greatly appreciated. Thanks!

1 Like