Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retire distutils from Python code #3389

Open
fhechtAdobe opened this issue Nov 1, 2024 · 9 comments
Open

Retire distutils from Python code #3389

fhechtAdobe opened this issue Nov 1, 2024 · 9 comments
Labels
build Build-related issue/PR good first issue Indicates a good issue for first-time contributors help wanted Indicates an issue where help and/or a pull request from the community would be very welcome

Comments

@fhechtAdobe
Copy link

Description of Issue

The distutils module is considered deprecated and has been removed in Python 3.12. That means the OpenUSD code (v24.11) compiles against Python 3.12, but then hits a runtime error when launching usdview.

I understand that the VFX platform for CY2025 is still targeting Python 3.11.x, but this was fixed for the build script (even though this ticket about the issue was closed: #2817) and there are only two functions from distutils still in use:

from distutils.spawn import find_executable which is easily replaceable with shutil.which. And distutils.util.strtobool, which does not have a direct replacement, but should be easy. See also https://peps.python.org/pep-0632/

It would be nice to improve the Python 3.12 support by taking this small extra step. Thanks!

@nvmkuruc
Copy link
Collaborator

nvmkuruc commented Nov 1, 2024

Agree that this would be helpful. 👍

@asluk asluk added the build Build-related issue/PR label Nov 1, 2024
@nvmkuruc nvmkuruc added help wanted Indicates an issue where help and/or a pull request from the community would be very welcome good first issue Indicates a good issue for first-time contributors labels Nov 2, 2024
@jesschimein
Copy link
Collaborator

Filed as internal issue #USD-10385

@mscherotter
Copy link

mscherotter commented Jan 15, 2025

On Windows 11,

  1. I just cloned the source
  2. Ran the python build script C:\> python OpenUSD\build_scripts\build_usd.py "C:\path\to\my_usd_install_dir"
  3. Built the code in Visual Studio 2022
  4. tried to run the sample asset usdview OpenUSD/extras/usd/tutorials/convertingLayerFormats/Sphere.usda
    I got this error - it looks like there is still a dependency on distutils. Please advise:

D:\Source\openusd_install\bin>usdview D:\Source\Repos\OpenUSD\extras\usd\tutorials\convertingLayerFormats\Sphere.usda
Traceback (most recent call last):
  File "D:\Source\openusd_install\bin\usdview", line 11, in <module>
    import pxr.Usdviewq as Usdviewq
  File "d:\source\openusd_install\lib\python\pxr\Usdviewq\__init__.py", line 17, in <module>
    from .appController import AppController
  File "d:\source\openusd_install\lib\python\pxr\Usdviewq\appController.py", line 35, in <module>
    from .layerStackContextMenu import LayerStackContextMenu
  File "d:\source\openusd_install\lib\python\pxr\Usdviewq\layerStackContextMenu.py", line 13, in <module>
    from pxr.UsdUtils.toolPaths import FindUsdBinary
  File "d:\source\openusd_install\lib\python\pxr\UsdUtils\toolPaths.py", line 10, in <module>
    from distutils.spawn import find_executable
ModuleNotFoundError: No module named 'distutils'

@beersandrew
Copy link
Contributor

Hey @mscherotter

I'm unable to reproduce, as I can run usdview on Windows on this branch.

One thing to check / make sure of is that you set your PATH and PYTHONPATH after building with the python build script, or since it appears you're running usdview directly from the bin directory, make sure you're in the directory that you built off this branch

@mscherotter
Copy link

mscherotter commented Jan 24, 2025

Thanks for the response. I have these set as:

PYTHON=C:\Users\syner\AppData\Local\Programs\Python\Python310
PYTHONPATH=d:\source\openusd_install\lib\python
PATH=...C:\Users\syner\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\Scripts;d:\source\openusd_install\bin;d:\source\openusd_install\lib...

does that look correct?

Michael

@beersandrew
Copy link
Contributor

I think you need to add the USD paths to your PATH as well. Here are my steps:

  1. Clone the repo in C:\my\cloned\repo\dir make sure you're on the 3389-Remove-distutils branch
  2. Build: python build_scripts\build_usd.py C:\my\build\dir\usd-no-dist-utils
  3. Add C:\my\build\dir\usd-no-dist-utils\lib to your PATH
  4. Add C:\my\build\dir\usd-no-dist-utils\bin to your PATH
  5. Add C:\my\build\dir\usd-no-dist-utils\lib\python to your PYTHONPATH
  6. Open a new terminal: usdview C:\my\cloned\repo\dir\OpenUSD\extras\usd\tutorials\referencingLayers\HelloWorld.usda
  7. View the blue sphere

@mscherotter
Copy link

mscherotter commented Jan 24, 2025 via email

@beersandrew
Copy link
Contributor

https://github.com/beersandrew/USD/branches

it's here, on my fork

@mypreciously
Copy link

mypreciously commented Feb 2, 2025

Hello - I am running into this issue while using Python 3.13.1 on my machine. This is just from running usdview --help. What is the workaround for this?

Edit/Update -

Ah, I re-read and followed @beersandrew steps above, and it worked! This was on macOS Sequoia 15.1 (instead of Winodws). I also had to make sure I cleaned up/removed my previous environment variables that pointed to the previous build:

I think you need to add the USD paths to your PATH as well. Here are my steps:

  1. Clone the repo in C:\my\cloned\repo\dir make sure you're on the 3389-Remove-distutils branch
  2. Build: python build_scripts\build_usd.py C:\my\build\dir\usd-no-dist-utils
  3. Add C:\my\build\dir\usd-no-dist-utils\lib to your PATH
  4. Add C:\my\build\dir\usd-no-dist-utils\bin to your PATH
  5. Add C:\my\build\dir\usd-no-dist-utils\lib\python to your PYTHONPATH
  6. Open a new terminal: usdview C:\my\cloned\repo\dir\OpenUSD\extras\usd\tutorials\referencingLayers\HelloWorld.usda
  7. View the blue sphere

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Build-related issue/PR good first issue Indicates a good issue for first-time contributors help wanted Indicates an issue where help and/or a pull request from the community would be very welcome
Projects
None yet
Development

No branches or pull requests

7 participants