tensorflow: ImportError: libtensorflow_cc.so.2: cannot open shared object file: No such file or directory
Click to expand!
Issue Type
Bug
Have you reproduced the bug with TF nightly?
No
Source
source
Tensorflow Version
tf 2.13.0
Custom Code
Yes
OS Platform and Distribution
Linux
Mobile device
No response
Python version
3.9
Bazel version
6.1.1
GCC/Compiler version
9.5.0
CUDA/cuDNN version
No response
GPU model and memory
No response
Current Behaviour?
I build the lastest TensorFlow code from source successfully with
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
Then I generate a TensorFlow whl successfully with
./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
But when I pip install this whl, import tensorflow got “ImportError: libtensorflow_cc.so.2: cannot open shared object file: No such file or directory”.
I found the whl file generated is only 80.64M. But I think it should be about 200M.
But there has libtensorflow_cc.so.2 file under path tensorflow/bazel-bin/tensorflow. I don’t know why it wasn’t packed into the whl file.
Standalone code to reproduce the issue
import tensorflow as tf
Relevant log output
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/data1/envs/xtc3.9/lib/python3.9/site-packages/tensorflow/__init__.py", line 38, in <module>
from tensorflow.python.tools import module_util as _module_util
File "/data1/envs/xtc3.9/lib/python3.9/site-packages/tensorflow/python/__init__.py", line 36, in <module>
from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
File "/data1/envs/xtc3.9/lib/python3.9/site-packages/tensorflow/python/pywrap_tensorflow.py", line 26, in <module>
self_check.preload_check()
File "/data1/envs/xtc3.9/lib/python3.9/site-packages/tensorflow/python/platform/self_check.py", line 63, in preload_check
from tensorflow.python.platform import _pywrap_cpu_feature_guard
ImportError: libtensorflow_cc.so.2: cannot open shared object file: No such file or directory
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 16 (7 by maintainers)
I need to build a .whl that actually works, and “–config monolithic” fails due to issue #60052.
Why is the pip package missing libtensorflow_cc.so.2? r2.12 does not have this problem. Is it possible to reopen this issue?
Hi @ProgrammerPeter ,
Apologies for the delayed response. By default Tensorflow builds are not monolithic. Please refer to attached source file for same.
https://github.com/tensorflow/tensorflow/blob/f0b8b9a1457bcc8d83716b2034d3d6501693c7d0/.bazelrc#L98C1
To get a single shared file we need to use
--config=monolithicflag. Could you please confirm whether you have tested the build with this flag ?IMO, even with non monolithic builds the SO file also should be added to the wheel. Starting from TF2.13, tensorflow builds for Linux uses clang compiler inplace of GCC.Please refer attached documentation. Can you try the build with clang 16.0 and let us know if that makes difference.
Thanks!
It seems like the issue is related to the missing shared library libtensorflow_cc.so.2. This can happen if the library is not found in the expected location or if it is not included in the TensorFlow package.
Here are some things you could try to resolve the issue:
Check if the library is installed: Use the find command to search for the library in your system. If it is found, check if the path to the library is included in the LD_LIBRARY_PATH environment variable.
Try rebuilding TensorFlow: The issue could be related to a problem during the build process. Try rebuilding TensorFlow using the --config=monolithic flag to ensure that all libraries are included.
Check if there are any conflicts: If you have multiple versions of TensorFlow installed, there may be conflicts between the different versions. Make sure that you are importing the correct version of TensorFlow.
Try installing TensorFlow using pip: Instead of building TensorFlow from source, try installing it using pip. This should ensure that all the required libraries are included in the package.
Hopefully, one of these suggestions will help you resolve the issue.
@ProgrammerPeter Hi, Thanks for opening the issue,
It seems like the libtensorflow_cc.so.2 file is not being included in the generated TensorFlow wheel file. Here are a few suggestions to fix the issue:
Try building the TensorFlow package again with the following command:
This command will build the TensorFlow package with support for CUDA-enabled GPUs. If you don’t have a GPU, you can skip the --config=cuda flag.
Check the contents of the generated wheel file to see if the libtensorflow_cc.so.2 file is present. You can do this using the following command:
This command will display information about the installed TensorFlow package, including its location on your system. Once you have the location of the package, you can navigate to the package directory and inspect its contents.
If the libtensorflow_cc.so.2 file is missing from the package, you can manually copy it into the appropriate directory. The directory structure of the TensorFlow package should be similar to the following:
The libtensorflow_cc.so.2 file should be placed in the tensorflow directory alongside the other Python modules.
If none of the above solutions work, try building TensorFlow from source again, but this time with the following command:
This command will build a monolithic TensorFlow package, which includes all of the necessary shared libraries.