'Tensorflow Op: how to include libtensorflow_framework.so?
I followed the instructions of this tutorial:
https://www.tensorflow.org/extend/adding_an_op#implement_the_gradient_in_python.
There is this comment provided: g++ -std=c++11 -shared zero_out.cc -o zero_out.so -fPIC -I$TF_INC -I$TF_INC/external/nsync/public -L$TF_LIB -ltensorflow_framework -O2
But the linker cannot find -ltensorflow_framework
(it should be a tensorflow_frameowork.so file!?)
After some research, I found following links:
- https://github.com/tensorflow/tensorflow/issues/1569
- https://github.com/eaplatanios/tensorflow_scala/issues/26 --> I downloaded the .jar and linked it via
-l/pathto/tensorflow_framework.so
, still thefatal error: tensorflow/core/framework/op_kernel.h: No such file or directory
is not found. - https://github.com/tensorflow/tensorflow/issues/1270 last comment does not work and so does not help me.
I tried to search for sudo find /usr/. -name "tensorflow_framework.so"
recursively but I could not find anything. Tensorflow is installed for sure via anaconda and I also cloned and compiled the repository from source.
How to find a way to include the -ltensorflow_framework
?
Solution 1:[1]
One answer, I have found:
I have installed my python via anaconda2 and I always tried to find out TF_INC and TF_LIB when I activated my repository source activate <env>
. and the could not found any ~/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow
*.so files
This time I went out every python environment with the shell command source deactivate
and I typed the following command
python -c 'import tensorflow as tf; print(tf.sysconfig.get_lib())'
Now, I got a different path: ~/anaconda2/lib/python2.7/site-packages/tensorflow
, where the lib libtensorflow_framework.so
is located.
Solution 2:[2]
In my case, the file libtensorflow_framework.so.1
existed inside my TF_LIB
directory instead of libtensorflow_framework.so
. In order to solve this issue, I had to create a symbolic link as follows:
ln -s libtensorflow_framework.so.1 libtensorflow_framework.so
Source: Tensorflow NotFoundError: libtensorflow_framework.so: cannot open shared file or directory
Solution 3:[3]
tensorflow_framework is not used before Tensorflow 1.4.1
When you call python from the shell make sure you are calling the right one:
TF_LIB = $(shell python -c 'import tensorflow; print(tensorflow.sysconfig.get_lib())')
or
TF_LIB = $(shell python3 -c 'import tensorflow; print(tensorflow.sysconfig.get_lib())')
Solution 4:[4]
To be more clear:
- Get the path from
python -c 'import tensorflow as tf; print(tf.sysconfig.get_lib())'
, and there is a libtensorflow_framework.so.1 inside the directory. Say/home/.../lib/python3.7/site-packages/tensorflow_core/libtensorflow_framework.so.1
- Run
ln -s /home/.../lib/python3.7/site-packages/tensorflow_core/libtensorflow_framework.so.1 /home/.../lib/python3.7/site-packages/tensorflow_core/libtensorflow_framework.so
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | j35t3r |
Solution 2 | Moiz Sajid |
Solution 3 | rigo |
Solution 4 | MaizeMaze |