tensorflow / tensorflow/tensorflow

DYLD_LIBRARY_PATH cannot be pass in create_tensorflow.python_api_tf_python_api_gen_v2 on macosx

Open
#112,309 0 comments 0 reactions 1 assignee View on GitHub

@Venkat6871 is already working on this.

Since Mar 13, 2026.

comp:core subtype:macOS TF 2.9 type:build/install
Dominant language
C++
Stars
200k
Forks
76.9k
Avg merge
2d 3h
Merged PRs (30d)
433

Description

Issue type

Build/Install

Have you reproduced the bug with TensorFlow Nightly?

No

Source

source

TensorFlow version

tf 2.9

Custom code

Yes

OS platform and distribution

macosx 10.13.6

Mobile device

No response

Python version

3.9.18

Bazel version

5.2.1

GCC/compiler version

Apple LLVM version 10.0.1 (clang-1001.0.46.4)

CUDA/cuDNN version

Cuda compilation tools, release 10.1, V10.1.243, cuDNN 7

GPU model and memory

gtx 1080ti 11GB

Current behavior?

I'v build tf 2.9 use this repo, with a fixed bazel 5.2.1 this repo

after many hours compiling, it fails on this step

Executing genrule //tensorflow:tf_python_api_gen_v2 failed: (Segmentation fault): bash failed: error executing command

 W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.10.1.dylib'; dlerror: dlopen(libcudart.10.1.dylib, 6): image not found

then I add this argument --action_env DYLD_LIBRARY_PATH=/usr/local/cuda/lib and rerun the build script,
it takes another hours to rebuild everything, then fails with same error.

I check the log carefully, it seems the env DYLD_LIBRARY_PATH variable was not pass into the python environment.

ERROR: /Volumes/Data/git/tensorflow-osx/tensorflow/BUILD:1263:19: Executing genrule //tensorflow:tf_python_api_gen_v2 failed: (Segmentation fault): bash failed: error executing command 
  (cd /private/var/tmp/_bazel_xlla/5e0f44411be79c51a887c448365c0535/execroot/org_tensorflow && \
  exec env - \
    CUDA_TOOLKIT_PATH=/usr/local/cuda \
    DYLD_LIBRARY_PATH=/usr/local/cuda/lib \
    GCC_HOST_COMPILER_PATH=/usr/bin/gcc \
    PATH='/usr/local/opt/bison/bin:/usr/local/opt/php@8.3/sbin:/usr/local/opt/php@8.3/bin:/usr/local/opt/curl/bin:/Users/xlla/Library/Android/Sdk/tools:/Users/xlla/Library/Android/Sdk/platform-tools:/usr/local/cuda/bin:/Users/xlla/.cargo/bin:/usr/local/bin:/usr/local/sbin:/opt/X11/bin:/usr/local/opt/ruby/bin:/usr/local/opt/openssl@1.1/bin:/usr/local/opt/tcl-tk/bin:/Users/xlla/git/moddable/build/bin/mac/release:/Applications/Wine Stable.app/Contents/Resources/wine/bin:/Users/xlla/.rvm/gems/ruby-2.2.3/bin:/Users/xlla/.rvm/gems/ruby-2.2.3@global/bin:/Users/xlla/.rvm/rubies/ruby-2.2.3/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/opt/X11/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/usr/local/CrossPack-AVR/bin:/Users/xlla/.rvm/bin:/usr/local/cuda/bin:/Users/xlla/.local/bin' \
    PYTHON_BIN_PATH=/usr/local/opt/python@3.9/bin/python3.9 \
    PYTHON_LIB_PATH=/usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages \
    TF2_BEHAVIOR=1 \
    TF_CUDA_COMPUTE_CAPABILITIES=6.1 \
  /bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; bazel-out/host/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2 

As you can see, DYLD_LIBRARY_PATH=/usr/local/cuda/lib was set before create_tensorflow.python_api_tf_python_api_gen_v2 get launch, I have modified it to output env, all above was present except DYLD_LIBRARY_PATH !

then I add DYLD_LIBRARY_PATH to os.environ directly inside create_tensorflow.python_api_tf_python_api_gen_v2 , and manual execute the command

bazel-out/host/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2 --root_init_template=tensorflow/api_template.__init__.py --apidir=bazel-out/darwin-opt/bin/tensorflow_api/v2/

...

bazel-out/darwin-opt/bin/tensorflow/_api/v2/compat/v2/compat/v2/compat/__init__.py

it works without any errors.

when I try re-run the bazel build //tensorflow/tools/pip_package:build_pip_package , it regenerate the tensorflow.python_api_tf_python_api_gen_v2 , so it get lost the env DYLD_LIBRARY_PATH and fails again.

my questions is:

  1. how to properly pass in DYLD_LIBRARY_PATH for tensorflow/bazel build on macos ?

  2. how to prevent bazel overwrite my modifications to create_tensorflow.python_api_tf_python_api_gen_v2, so build process can continue?

  3. since I have execute that step manually , the required files was generated, how to skip this step and continue build?

Standalone code to reproduce the issue
bazel build --config=opt --copt=-mssse3 --copt=-mfma --copt=-mcx16 --copt=-msse4.1 --copt=-msse4.2 --copt=-mpopcnt --copt=-mavx --config=noaws --config=nonccl  --verbose_failures --action_env DYLD_LIBRARY_PATH=/usr/local/cuda/lib //tensorflow/tools/pip_package:build_pip_package
Relevant log output
INFO: Found applicable config definition build:macos in file /Volumes/Data/git/tensorflow-osx/.bazelrc: --apple_platform_type=macos --copt=-DGRPC_BAZEL_BUILD --copt=-w --define=PREFIX=/usr --define=LIBDIR=$(PREFIX)/lib --define=INCLUDEDIR=$(PREFIX)/include --define=PROTOBUF_INCLUDE_PATH=$(PREFIX)/include --cxxopt=-std=c++14 --host_cxxopt=-std=c++14
INFO: Analyzed target //tensorflow/tools/pip_package:build_pip_package (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /Volumes/Data/git/tensorflow-osx/tensorflow/BUILD:1263:19: Executing genrule //tensorflow:tf_python_api_gen_v2 failed: (Segmentation fault): bash failed: error executing command 
  (cd /private/var/tmp/_bazel_xlla/5e0f44411be79c51a887c448365c0535/execroot/org_tensorflow && \
  exec env - \
    CUDA_TOOLKIT_PATH=/usr/local/cuda \
    DYLD_LIBRARY_PATH=/usr/local/cuda/lib \
    GCC_HOST_COMPILER_PATH=/usr/bin/gcc \
    PATH='/usr/local/opt/bison/bin:/usr/local/opt/php@8.3/sbin:/usr/local/opt/php@8.3/bin:/usr/local/opt/curl/bin:/Users/xlla/Library/Android/Sdk/tools:/Users/xlla/Library/Android/Sdk/platform-tools:/usr/local/cuda/bin:/Users/xlla/.cargo/bin:/usr/local/bin:/usr/local/sbin:/opt/X11/bin:/usr/local/opt/ruby/bin:/usr/local/opt/openssl@1.1/bin:/usr/local/opt/tcl-tk/bin:/Users/xlla/git/moddable/build/bin/mac/release:/Applications/Wine Stable.app/Contents/Resources/wine/bin:/Users/xlla/.rvm/gems/ruby-2.2.3/bin:/Users/xlla/.rvm/gems/ruby-2.2.3@global/bin:/Users/xlla/.rvm/rubies/ruby-2.2.3/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/opt/X11/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/usr/local/CrossPack-AVR/bin:/Users/xlla/.rvm/bin:/usr/local/cuda/bin:/Users/xlla/.local/bin' \
    PYTHON_BIN_PATH=/usr/local/opt/python@3.9/bin/python3.9 \
    PYTHON_LIB_PATH=/usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages \
    TF2_BEHAVIOR=1 \
    TF_CUDA_COMPUTE_CAPABILITIES=6.1 \
  /bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; bazel-out/host/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2 --root_init_template=tensorflow/api_template.__init__.py --apidir=bazel-out/darwin-opt/bin/tensorflow_api/v2/ --apiname=tensorflow --apiversion=2 --compat_apiversion=1 --compat_apiversion=2  --compat_init_template=tensorflow/compat_template_v1.__init__.py --compat_init_template=tensorflow/compat_template.__init__.py --loading=default --packages=tensorflow.python,tensorflow.dtensor.python.api,tensorflow.dtensor.python.d_checkpoint,tensorflow.dtensor.python.d_variable

skip very long __init__.py list

 bazel-out/darwin-opt/bin/tensorflow/_api/v2/compat/v2/compat/v2/compat/__init__.py')
# Configuration: d4cd6687cd9a042d9e1d71239049844dd44213370ae33c3fe02a98a91c332c95
# Execution platform: @local_execution_config_platform//:platform
2026-03-13 17:01:22.585462: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.10.1.dylib'; dlerror: dlopen(libcudart.10.1.dylib, 6): image not found
2026-03-13 17:01:22.585546: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.