tensorflow: Problems compiling TensorFlow on M1 Mac within Rosetta

Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): no
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): macOS Monterey 12.1, MacBook Pro M1 2021
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: n/a
  • TensorFlow installed from (source or binary): source
  • TensorFlow version (use command below): 2.7.1 (couldn’t use the command because the import fails)
  • Python version: 3.8.5 (Miniconda)
  • Bazel version (if compiling from source): Build label: 5.0.0 Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar Build time: Wed Jan 19 14:15:55 2022 (1642601755) Build timestamp: 1642601755 Build timestamp as int: 1642601755
  • GCC/Compiler version (if compiling from source): Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1 Apple clang version 13.0.0 (clang-1300.0.29.30) Target: x86_64-apple-darwin21.2.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin
  • CUDA/cuDNN version: n/a
  • GPU model and memory: n/a

You can collect some of this information using our environment capture script You can also obtain the TensorFlow version with:

  1. TF 1.0: python -c "import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)"
  2. TF 2.0: python -c "import tensorflow as tf; print(tf.version.GIT_VERSION, tf.version.VERSION)"

Describe the current behavior

I’ve been trying to compile TensorFlow from source using a Rosetta terminal. I use Miniconda. Here is what I end up with:

(sandbox) ➜  wheels python -c "import tensorflow as tf"
Traceback (most recent call last):
  File "/Users/come/miniconda3/envs/sandbox/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 64, in <module>
    from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: dlopen(/Users/come/miniconda3/envs/sandbox/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 0x0006): symbol not found in flat namespace '_PyCMethod_New'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/come/miniconda3/envs/sandbox/lib/python3.8/site-packages/tensorflow/__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "/Users/come/miniconda3/envs/sandbox/lib/python3.8/site-packages/tensorflow/python/__init__.py", line 40, in <module>
    from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
  File "/Users/come/miniconda3/envs/sandbox/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 79, in <module>
    raise ImportError(
ImportError: Traceback (most recent call last):
  File "/Users/come/miniconda3/envs/sandbox/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 64, in <module>
    from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: dlopen(/Users/come/miniconda3/envs/sandbox/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 0x0006): symbol not found in flat namespace '_PyCMethod_New'


Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/errors for some common causes and solutions.
If you need help, create an issue at https://github.com/tensorflow/tensorflow/issues and include the entire stack trace above this error message.

Describe the expected behavior

The TensorFlow library to be imported without issue.

Contributing

  • Do you want to contribute a PR? (yes/no): no
  • Briefly describe your candidate solution(if contributing): n/a

Standalone code to reproduce the issue Provide a reproducible test case that is the bare minimum necessary to generate the problem. If possible, please share a link to Colab/Jupyter/any notebook.

(base) ➜  wheels arch
i386
(base) ➜  wheels git clone https://github.com/tensorflow/tensorflow.git
(base) ➜  wheels cd tensorflow
(base) ➜  tensorflow git:(master) git checkout v2.7.1
(base) ➜  tensorflow git:(2a0f59ecfe6) ./configure
(base) ➜  tensorflow git:(2a0f59ecfe6) bazel build //tensorflow/tools/pip_package:build_pip_package
(base) ➜  tensorflow git:(2a0f59ecfe6) ./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
(base) ➜  tensorflow git:(2a0f59ecfe6) mv /tmp/tensorflow_pkg/tensorflow-2.7.1-cp39-cp39-macosx_12_0_x86_64.whl 
 tmp/tensorflow_pkg/tensorflow-2.7.1-py3-none-any.whl
(base) ➜  tensorflow git:(2a0f59ecfe6) conda create -y --name sandbox python=3.8.5
(base) ➜  tensorflow git:(2a0f59ecfe6) conda activate sandbox
(sandbox) ➜  tensorflow git:(2a0f59ecfe6) pip install /tmp/tensorflow_pkg/tensorflow-2.7.1-py3-none-any.whl
(sandbox) ➜  tensorflow git:(2a0f59ecfe6) python -c "import tensorflow as tf"

Other info / logs Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

Any help would be really appreciated. Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 15 (4 by maintainers)

Most upvoted comments

M1 related build issues are officially not supported by Tensorflow, since we currently don’t have Tensorflow build for M1 officially from us. Please refer to this document for building Tensorflow. If you have any additional queries, you can post your issues on https://developer.apple.com/forums/. Thanks!

Please refer the Note section in the document here and let us know if this helps. Thanks!

That document is about installing TensorFlow, not building it, and as we have already discussed in this GitHub thread, the OP is asking about building TF, not installing it.