Importing pxr module has changed in 5.5+

In Unreal 5.5+ you have to explicitly import submodules from pxr

5.4

import pxr

help(pxr.UsdGeom)

Works

5.5+

LogPython: import pxr

LogPython: print(pxr.UsdGeom.LinearUnits.feet)

LogPython: Error: Traceback (most recent call last):

LogPython: Error: File “<string>”, line 1, in <module>

LogPython: Error: AttributeError: module ‘pxr’ has no attribute ‘UsdGeom’

LogPython: import pxr.UsdGeom

LogPython: print(pxr.UsdGeom.LinearUnits.feet)

LogPython: 0.3048

import pxr
for each in pxr.__all__:
    exec('import pxr.{}'.format(each))

Have to do that in order to access something like pxr.UsdGeom, etc.

Steps to Reproduce
import pxr

help(pxr.UsdGeom)

AttributeError: module 'pxr' has no attribute 'UsdGeom'

Hi Christopher,

While it’s true that this behavior changed between 5.4 and 5.5, the behavior as of 5.5 is technically the correct one so you have to import what you use instead of relying on import pxr to import everything.

We do the same for our own scripts: import pxr then from pxr import whatever module we need in the script.

Best regards,

Anousack

It most certainly is not technically correct, and I have that confirmed by Pixar.

A suggestion you could try is to modify your Engine\Plugins\Runtime\USDCore\Content\Python\Lib\Win64\X64\site-packages\pxr\__init__.py and add this to the file:

from . import *This way you won’t need to loop over __all__ to import the pxr submodules in your scripts.

This is the solution we use

    import pxr
    for name in pxr.__all__:
        importlib.import_module(f"pxr.{name}")

It’s just that we shouldn’t *need* to

Hi,

Glad to hear you’ve got it solved on your end. It’s hard to say exactly why this wasn’t required before, though its likely that either some other script imported pxr.UsdGeom (since everything will be imported in the same Unreal namespace), or perhaps there was a bug with our bundled Python implementation that was fixed. We’re in a tricky spot since changing this would cause incorrect behavior elsewhere, and the current requirement to explicitly import pxr.UsdGeom matches what I’m seeing in a Python script outside of Unreal as well.

Best,

Cody