Skip to content

RPATH Fix for portable_lib Python Extension - #13254

Merged
larryliu0820 merged 1 commit into
release/0.7from
0.7_release_ready_pip_wheel_fix
Aug 9, 2025
Merged

RPATH Fix for portable_lib Python Extension#13254
larryliu0820 merged 1 commit into
release/0.7from
0.7_release_ready_pip_wheel_fix

Conversation

@mergennachin

@mergennachinmergennachin commented Aug 9, 2025

Copy link
Copy Markdown
Contributor

RPATH Fix for portable_lib Python Extension

Problem: The _portable_lib.so Python extension built on CI couldn't find PyTorch libraries when installed locally because it had hardcoded absolute paths from
the CI build environment.

Error:
ImportError: dlopen(.../_portable_lib.cpython-311-darwin.so, 0x0002):
Library not loaded: @rpath/libtorch_python.dylib
Referenced from: .../executorch/extension/pybindings/_portable_lib.cpython-311-darwin.so
Reason: tried: '/Users/runner/work/_temp/.../torch/lib/libtorch_python.dylib' (no such file)

Root Cause: The CMake build was linking to PyTorch libraries using absolute paths from the build environment, without setting proper relative RPATHs for
runtime library resolution.

Solution: Added platform-specific relative RPATH settings to the portable_lib target in /Users/mnachin/executorch/CMakeLists.txt (lines 657-669):

  • macOS: Uses @loader_path/../../../torch/lib to find PyTorch libraries relative to the .so file location
  • Linux: Uses $ORIGIN/../../../torch/lib for the same purpose
  • Sets both BUILD_RPATH and INSTALL_RPATH to ensure consistency

Impact: This allows the wheel-packaged _portable_lib.so to find PyTorch libraries regardless of the installation location, fixing the runtime linking issue
when using ExecutorTorch wheels built on CI.

Note: The same fix may be needed for _training_lib if it experiences similar issues.

Test Plan:

 # Build the wheel locally
python setup.py bdist_wheel
# create fresh conda env
conda create -yn executorch_test_11 python=3.11.0 && conda activate executorch_test_11
# install pip install ./dist/executorch-*.whl
# Verify
python -c "from executorch.extension.pybindings._portable_lib import _load_for_executorch; print('Success!')"

@pytorch-bot

pytorch-botBot commented Aug 9, 2025

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/13254

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure, 22 Pending

As of commit af215ba with merge base de24489 (image):

NEW FAILURE - The following job has failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-clameta-claBot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 9, 2025
@mergennachin
mergennachinforce-pushed the 0.7_release_ready_pip_wheel_fix branch from 45f821c to 4230024CompareAugust 9, 2025 08:42
@mergennachinmergennachin changed the title 0.7 release ready pip wheel fixRPATH Fix for portable_lib Python ExtensionAug 9, 2025
@mergennachin

Copy link
Copy Markdown
ContributorAuthor

Note: if it's successful, make sure to merge to main as well

@mergennachinmergennachin mentioned this pull request Aug 9, 2025
Problem: The _portable_lib.so Python extension built on CI couldn't find PyTorch libraries when installed locally because it had hardcoded absolute paths from
the CI build environment.
Error:
ImportError: dlopen(.../_portable_lib.cpython-311-darwin.so, 0x0002):
Library not loaded: @rpath/libtorch_python.dylib
Referenced from: .../executorch/extension/pybindings/_portable_lib.cpython-311-darwin.so
Reason: tried: '/Users/runner/work/_temp/.../torch/lib/libtorch_python.dylib' (no such file)
Root Cause: The CMake build was linking to PyTorch libraries using absolute paths from the build environment, without setting proper relative RPATHs for
runtime library resolution.
Solution: Added platform-specific relative RPATH settings to the portable_lib target in /Users/mnachin/executorch/CMakeLists.txt (lines 657-669):
- macOS: Uses @loader_path/../../../torch/lib to find PyTorch libraries relative to the .so file location
- Linux: Uses $ORIGIN/../../../torch/lib for the same purpose
- Sets both BUILD_RPATH and INSTALL_RPATH to ensure consistency
Impact: This allows the wheel-packaged _portable_lib.so to find PyTorch libraries regardless of the installation location, fixing the runtime linking issue
when using ExecutorTorch wheels built on CI.
Note: The same fix may be needed for _training_lib if it experiences similar issues.
@mergennachin
mergennachinforce-pushed the 0.7_release_ready_pip_wheel_fix branch from 4230024 to af215baCompareAugust 9, 2025 09:14
Comment threadCMakeLists.txt
@larryliu0820
larryliu0820force-pushed the 0.7_release_ready_pip_wheel_fix branch from 0793348 to af215baCompareAugust 9, 2025 22:26
@larryliu0820
larryliu0820 merged commit 38062f8 into release/0.7Aug 9, 2025
366 of 379 checks passed
@larryliu0820
larryliu0820 deleted the 0.7_release_ready_pip_wheel_fix branch August 9, 2025 22:53
@mergennachin

Copy link
Copy Markdown
ContributorAuthor

@pytorchbot cherry-pick --onto main -c critical

pytorchbot pushed a commit that referenced this pull request Aug 11, 2025
RPATH Fix for portable_lib Python Extension
Problem: The _portable_lib.so Python extension built on CI couldn't find
PyTorch libraries when installed locally because it had hardcoded
absolute paths from
the CI build environment.
Error:
ImportError: dlopen(.../_portable_lib.cpython-311-darwin.so, 0x0002):
Library not loaded: @rpath/libtorch_python.dylib
Referenced from:
.../executorch/extension/pybindings/_portable_lib.cpython-311-darwin.so
Reason: tried:
'/Users/runner/work/_temp/.../torch/lib/libtorch_python.dylib' (no such
file)
Root Cause: The CMake build was linking to PyTorch libraries using
absolute paths from the build environment, without setting proper
relative RPATHs for
runtime library resolution.
Solution: Added platform-specific relative RPATH settings to the
portable_lib target in /Users/mnachin/executorch/CMakeLists.txt (lines
657-669):
- macOS: Uses @loader_path/../../../torch/lib to find PyTorch libraries
relative to the .so file location
- Linux: Uses $ORIGIN/../../../torch/lib for the same purpose
- Sets both BUILD_RPATH and INSTALL_RPATH to ensure consistency
Impact: This allows the wheel-packaged _portable_lib.so to find PyTorch
libraries regardless of the installation location, fixing the runtime
linking issue
when using ExecutorTorch wheels built on CI.
Note: The same fix may be needed for _training_lib if it experiences
similar issues.
Test Plan:
```
# Build the wheel locally
python setup.py bdist_wheel
# create fresh conda env
conda create -yn executorch_test_11 python=3.11.0 && conda activate executorch_test_11
# install
pip install ./dist/executorch-*.whl
# Verify
python -c "from executorch.extension.pybindings._portable_lib import _load_for_executorch; print('Success!')"
```
(cherry picked from commit 38062f8)
@pytorchbot

Copy link
Copy Markdown
Collaborator

Cherry picking #13254

The cherry pick PR is at #13290 and it is recommended to link a critical cherry pick PR with an issue.

Details for Dev Infra team Raised by workflow job

GregoryComer pushed a commit to GregoryComer/executorch that referenced this pull request Sep 18, 2025
RPATH Fix for portable_lib Python Extension
Problem: The _portable_lib.so Python extension built on CI couldn't find
PyTorch libraries when installed locally because it had hardcoded
absolute paths from
the CI build environment.
Error:
ImportError: dlopen(.../_portable_lib.cpython-311-darwin.so, 0x0002):
Library not loaded: @rpath/libtorch_python.dylib
Referenced from:
.../executorch/extension/pybindings/_portable_lib.cpython-311-darwin.so
Reason: tried:
'/Users/runner/work/_temp/.../torch/lib/libtorch_python.dylib' (no such
file)
Root Cause: The CMake build was linking to PyTorch libraries using
absolute paths from the build environment, without setting proper
relative RPATHs for
runtime library resolution.
Solution: Added platform-specific relative RPATH settings to the
portable_lib target in /Users/mnachin/executorch/CMakeLists.txt (lines
657-669):
- macOS: Uses @loader_path/../../../torch/lib to find PyTorch libraries
relative to the .so file location
- Linux: Uses $ORIGIN/../../../torch/lib for the same purpose
- Sets both BUILD_RPATH and INSTALL_RPATH to ensure consistency
Impact: This allows the wheel-packaged _portable_lib.so to find PyTorch
libraries regardless of the installation location, fixing the runtime
linking issue
when using ExecutorTorch wheels built on CI.
Note: The same fix may be needed for _training_lib if it experiences
similar issues.
Test Plan:
```
# Build the wheel locally
python setup.py bdist_wheel
# create fresh conda env
conda create -yn executorch_test_11 python=3.11.0 && conda activate executorch_test_11
# install
pip install ./dist/executorch-*.whl
# Verify
python -c "from executorch.extension.pybindings._portable_lib import _load_for_executorch; print('Success!')"
```
GregoryComer pushed a commit to GregoryComer/executorch that referenced this pull request Sep 19, 2025
RPATH Fix for portable_lib Python Extension
Problem: The _portable_lib.so Python extension built on CI couldn't find
PyTorch libraries when installed locally because it had hardcoded
absolute paths from
the CI build environment.
Error:
ImportError: dlopen(.../_portable_lib.cpython-311-darwin.so, 0x0002):
Library not loaded: @rpath/libtorch_python.dylib
Referenced from:
.../executorch/extension/pybindings/_portable_lib.cpython-311-darwin.so
Reason: tried:
'/Users/runner/work/_temp/.../torch/lib/libtorch_python.dylib' (no such
file)
Root Cause: The CMake build was linking to PyTorch libraries using
absolute paths from the build environment, without setting proper
relative RPATHs for
runtime library resolution.
Solution: Added platform-specific relative RPATH settings to the
portable_lib target in /Users/mnachin/executorch/CMakeLists.txt (lines
657-669):
- macOS: Uses @loader_path/../../../torch/lib to find PyTorch libraries
relative to the .so file location
- Linux: Uses $ORIGIN/../../../torch/lib for the same purpose
- Sets both BUILD_RPATH and INSTALL_RPATH to ensure consistency
Impact: This allows the wheel-packaged _portable_lib.so to find PyTorch
libraries regardless of the installation location, fixing the runtime
linking issue
when using ExecutorTorch wheels built on CI.
Note: The same fix may be needed for _training_lib if it experiences
similar issues.
Test Plan:
```
# Build the wheel locally
python setup.py bdist_wheel
# create fresh conda env
conda create -yn executorch_test_11 python=3.11.0 && conda activate executorch_test_11
# install
pip install ./dist/executorch-*.whl
# Verify
python -c "from executorch.extension.pybindings._portable_lib import _load_for_executorch; print('Success!')"
```
GregoryComer pushed a commit to GregoryComer/executorch that referenced this pull request Sep 19, 2025
RPATH Fix for portable_lib Python Extension
Problem: The _portable_lib.so Python extension built on CI couldn't find
PyTorch libraries when installed locally because it had hardcoded
absolute paths from
the CI build environment.
Error:
ImportError: dlopen(.../_portable_lib.cpython-311-darwin.so, 0x0002):
Library not loaded: @rpath/libtorch_python.dylib
Referenced from:
.../executorch/extension/pybindings/_portable_lib.cpython-311-darwin.so
Reason: tried:
'/Users/runner/work/_temp/.../torch/lib/libtorch_python.dylib' (no such
file)
Root Cause: The CMake build was linking to PyTorch libraries using
absolute paths from the build environment, without setting proper
relative RPATHs for
runtime library resolution.
Solution: Added platform-specific relative RPATH settings to the
portable_lib target in /Users/mnachin/executorch/CMakeLists.txt (lines
657-669):
- macOS: Uses @loader_path/../../../torch/lib to find PyTorch libraries
relative to the .so file location
- Linux: Uses $ORIGIN/../../../torch/lib for the same purpose
- Sets both BUILD_RPATH and INSTALL_RPATH to ensure consistency
Impact: This allows the wheel-packaged _portable_lib.so to find PyTorch
libraries regardless of the installation location, fixing the runtime
linking issue
when using ExecutorTorch wheels built on CI.
Note: The same fix may be needed for _training_lib if it experiences
similar issues.
Test Plan:
```
# Build the wheel locally
python setup.py bdist_wheel
# create fresh conda env
conda create -yn executorch_test_11 python=3.11.0 && conda activate executorch_test_11
# install
pip install ./dist/executorch-*.whl
# Verify
python -c "from executorch.extension.pybindings._portable_lib import _load_for_executorch; print('Success!')"
```
GregoryComer added a commit that referenced this pull request Sep 19, 2025
**Note: This is an attempt to cherry-pick Mergen's RPATH fix from #13254
onto main. Fixes#14421.
Original description below.**
Problem: The _portable_lib.so Python extension built on CI couldn't find
PyTorch libraries when installed locally because it had hardcoded
absolute paths from
the CI build environment.
Error:
ImportError: dlopen(.../_portable_lib.cpython-311-darwin.so, 0x0002):
Library not loaded: @rpath/libtorch_python.dylib
Referenced from:
.../executorch/extension/pybindings/_portable_lib.cpython-311-darwin.so
Reason: tried:
'/Users/runner/work/_temp/.../torch/lib/libtorch_python.dylib' (no such
file)
Root Cause: The CMake build was linking to PyTorch libraries using
absolute paths from the build environment, without setting proper
relative RPATHs for
runtime library resolution.
Solution: Added platform-specific relative RPATH settings to the
portable_lib target in /Users/mnachin/executorch/CMakeLists.txt (lines
657-669):
- macOS: Uses @loader_path/../../../torch/lib to find PyTorch libraries
relative to the .so file location
- Linux: Uses $ORIGIN/../../../torch/lib for the same purpose
- Sets both BUILD_RPATH and INSTALL_RPATH to ensure consistency
Impact: This allows the wheel-packaged _portable_lib.so to find PyTorch
libraries regardless of the installation location, fixing the runtime
linking issue
when using ExecutorTorch wheels built on CI.
Note: The same fix may be needed for _training_lib if it experiences
similar issues.
Test Plan:
```
# Build the wheel locally
python setup.py bdist_wheel
# create fresh conda env
conda create -yn executorch_test_11 python=3.11.0 && conda activate executorch_test_11
# install
pip install ./dist/executorch-*.whl
# Verify
python -c "from executorch.extension.pybindings._portable_lib import _load_for_executorch; print('Success!')"
```
Co-authored-by: Mergen Nachin <mnachin@meta.com>
pytorchbot pushed a commit that referenced this pull request Sep 19, 2025
**Note: This is an attempt to cherry-pick Mergen's RPATH fix from #13254
onto main. Fixes#14421.
Original description below.**
Problem: The _portable_lib.so Python extension built on CI couldn't find
PyTorch libraries when installed locally because it had hardcoded
absolute paths from
the CI build environment.
Error:
ImportError: dlopen(.../_portable_lib.cpython-311-darwin.so, 0x0002):
Library not loaded: @rpath/libtorch_python.dylib
Referenced from:
.../executorch/extension/pybindings/_portable_lib.cpython-311-darwin.so
Reason: tried:
'/Users/runner/work/_temp/.../torch/lib/libtorch_python.dylib' (no such
file)
Root Cause: The CMake build was linking to PyTorch libraries using
absolute paths from the build environment, without setting proper
relative RPATHs for
runtime library resolution.
Solution: Added platform-specific relative RPATH settings to the
portable_lib target in /Users/mnachin/executorch/CMakeLists.txt (lines
657-669):
- macOS: Uses @loader_path/../../../torch/lib to find PyTorch libraries
relative to the .so file location
- Linux: Uses $ORIGIN/../../../torch/lib for the same purpose
- Sets both BUILD_RPATH and INSTALL_RPATH to ensure consistency
Impact: This allows the wheel-packaged _portable_lib.so to find PyTorch
libraries regardless of the installation location, fixing the runtime
linking issue
when using ExecutorTorch wheels built on CI.
Note: The same fix may be needed for _training_lib if it experiences
similar issues.
Test Plan:
```
# Build the wheel locally
python setup.py bdist_wheel
# create fresh conda env
conda create -yn executorch_test_11 python=3.11.0 && conda activate executorch_test_11
# install
pip install ./dist/executorch-*.whl
# Verify
python -c "from executorch.extension.pybindings._portable_lib import _load_for_executorch; print('Success!')"
```
Co-authored-by: Mergen Nachin <mnachin@meta.com>
(cherry picked from commit 641e737)
abhinaykukkadapu pushed a commit that referenced this pull request Sep 23, 2025
**Note: This is an attempt to cherry-pick Mergen's RPATH fix from #13254
onto main. Fixes#14421.
Original description below.**
Problem: The _portable_lib.so Python extension built on CI couldn't find
PyTorch libraries when installed locally because it had hardcoded
absolute paths from
the CI build environment.
Error:
ImportError: dlopen(.../_portable_lib.cpython-311-darwin.so, 0x0002):
Library not loaded: @rpath/libtorch_python.dylib
Referenced from:
.../executorch/extension/pybindings/_portable_lib.cpython-311-darwin.so
Reason: tried:
'/Users/runner/work/_temp/.../torch/lib/libtorch_python.dylib' (no such
file)
Root Cause: The CMake build was linking to PyTorch libraries using
absolute paths from the build environment, without setting proper
relative RPATHs for
runtime library resolution.
Solution: Added platform-specific relative RPATH settings to the
portable_lib target in /Users/mnachin/executorch/CMakeLists.txt (lines
657-669):
- macOS: Uses @loader_path/../../../torch/lib to find PyTorch libraries
relative to the .so file location
- Linux: Uses $ORIGIN/../../../torch/lib for the same purpose
- Sets both BUILD_RPATH and INSTALL_RPATH to ensure consistency
Impact: This allows the wheel-packaged _portable_lib.so to find PyTorch
libraries regardless of the installation location, fixing the runtime
linking issue
when using ExecutorTorch wheels built on CI.
Note: The same fix may be needed for _training_lib if it experiences
similar issues.
Test Plan:
```
# Build the wheel locally
python setup.py bdist_wheel
# create fresh conda env
conda create -yn executorch_test_11 python=3.11.0 && conda activate executorch_test_11
# install
pip install ./dist/executorch-*.whl
# Verify
python -c "from executorch.extension.pybindings._portable_lib import _load_for_executorch; print('Success!')"
```
Co-authored-by: Mergen Nachin <mnachin@meta.com>
(cherry picked from commit 641e737)
abhinaykukkadapu pushed a commit that referenced this pull request Sep 23, 2025
Co-authored-by: Gregory Comer <gjcomer@meta.com>
Co-authored-by: Mergen Nachin <mnachin@meta.com>
fix from #13254Fixes#14421.
StrycekSimon pushed a commit to nxp-upstream/executorch that referenced this pull request Sep 23, 2025
**Note: This is an attempt to cherry-pick Mergen's RPATH fix from pytorch#13254
onto main. Fixespytorch#14421.
Original description below.**
Problem: The _portable_lib.so Python extension built on CI couldn't find
PyTorch libraries when installed locally because it had hardcoded
absolute paths from
the CI build environment.
Error:
ImportError: dlopen(.../_portable_lib.cpython-311-darwin.so, 0x0002):
Library not loaded: @rpath/libtorch_python.dylib
Referenced from:
.../executorch/extension/pybindings/_portable_lib.cpython-311-darwin.so
Reason: tried:
'/Users/runner/work/_temp/.../torch/lib/libtorch_python.dylib' (no such
file)
Root Cause: The CMake build was linking to PyTorch libraries using
absolute paths from the build environment, without setting proper
relative RPATHs for
runtime library resolution.
Solution: Added platform-specific relative RPATH settings to the
portable_lib target in /Users/mnachin/executorch/CMakeLists.txt (lines
657-669):
- macOS: Uses @loader_path/../../../torch/lib to find PyTorch libraries
relative to the .so file location
- Linux: Uses $ORIGIN/../../../torch/lib for the same purpose
- Sets both BUILD_RPATH and INSTALL_RPATH to ensure consistency
Impact: This allows the wheel-packaged _portable_lib.so to find PyTorch
libraries regardless of the installation location, fixing the runtime
linking issue
when using ExecutorTorch wheels built on CI.
Note: The same fix may be needed for _training_lib if it experiences
similar issues.
Test Plan:
```
# Build the wheel locally
python setup.py bdist_wheel
# create fresh conda env
conda create -yn executorch_test_11 python=3.11.0 && conda activate executorch_test_11
# install
pip install ./dist/executorch-*.whl
# Verify
python -c "from executorch.extension.pybindings._portable_lib import _load_for_executorch; print('Success!')"
```
Co-authored-by: Mergen Nachin <mnachin@meta.com>
jirioc pushed a commit to nxp-upstream/executorch that referenced this pull request Dec 19, 2025
**Note: This is an attempt to cherry-pick Mergen's RPATH fix from pytorch#13254
onto main. Fixespytorch#14421.
Original description below.**
Problem: The _portable_lib.so Python extension built on CI couldn't find
PyTorch libraries when installed locally because it had hardcoded
absolute paths from
the CI build environment.
Error:
ImportError: dlopen(.../_portable_lib.cpython-311-darwin.so, 0x0002):
Library not loaded: @rpath/libtorch_python.dylib
Referenced from:
.../executorch/extension/pybindings/_portable_lib.cpython-311-darwin.so
Reason: tried:
'/Users/runner/work/_temp/.../torch/lib/libtorch_python.dylib' (no such
file)
Root Cause: The CMake build was linking to PyTorch libraries using
absolute paths from the build environment, without setting proper
relative RPATHs for
runtime library resolution.
Solution: Added platform-specific relative RPATH settings to the
portable_lib target in /Users/mnachin/executorch/CMakeLists.txt (lines
657-669):
- macOS: Uses @loader_path/../../../torch/lib to find PyTorch libraries
relative to the .so file location
- Linux: Uses $ORIGIN/../../../torch/lib for the same purpose
- Sets both BUILD_RPATH and INSTALL_RPATH to ensure consistency
Impact: This allows the wheel-packaged _portable_lib.so to find PyTorch
libraries regardless of the installation location, fixing the runtime
linking issue
when using ExecutorTorch wheels built on CI.
Note: The same fix may be needed for _training_lib if it experiences
similar issues.
Test Plan:
```
# Build the wheel locally
python setup.py bdist_wheel
# create fresh conda env
conda create -yn executorch_test_11 python=3.11.0 && conda activate executorch_test_11
# install
pip install ./dist/executorch-*.whl
# Verify
python -c "from executorch.extension.pybindings._portable_lib import _load_for_executorch; print('Success!')"
```
Co-authored-by: Mergen Nachin <mnachin@meta.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@mergennachin@pytorchbot@larryliu0820