Cannot import tensorflow_text
Question:
I have problem with importing tensorflow_text
I tried importing like below two methods but none of them worked
import tensorflow_text as text
import tensorflow_text as tf_text
My tensorflow version is 2.9.1
and python version is Python 3.7.13
. I tried installing tensorflow_text
using below two methods but none of them is working.
!pip install tensorflow-text
!pip install -U tensorflow-text==2.9.0
I am using colab, I also tried reinstalling tensorflow but it still generates below error.
NotFoundError:
/usr/local/lib/python3.7/distpackages/tensorflow_text/python/ops/_sentencepiece_tokenizer.so:
undefined symbol: _ZNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEEC1Ev
Answers:
Update, Sometimes you need to reinstall and update tensorflow
then install tensorflow_text
. (Because you need your tensorflow.__version__
and tensorflow_text.__version__
to have the same version)
!pip install -U tensorflow
!pip install -U tensorflow-text
import tensorflow as tf
import tensorflow_text as text
# Or install with a specific Version
!pip install -U "tensorflow==2.8.*"
!pip install -U "tensorflow-text==2.8.*"
import tensorflow as tf
import tensorflow_text as text
Old First, install tensorflow-text
version 2.8.*
like below:
!pip install -q -U "tensorflow-text==2.8.*"
Then import tensorflow-text
like below:
import tensorflow_text as text
I have tried I’mahdi’s answer and it was not working, but the following solution worked for me.
Here are the steps that solved it for me.
- Visit the Tensorflow-Text official site (https://www.tensorflow.org/text)
- There is a little scroll bar down the right side RUN IN COLAB NOTEBBOK you will see, click on it (else use this link https://colab.research.google.com/github/tensorflow/text/blob/master/docs/guide/bert_preprocessing_guide.ipynb)
- In this notebook, change runtime to GPU and RUN cell by cell until the setup section
- And then it will work (WAIT)
- Delete all other cells except 1st 2 cells of Setup section
- Then continue your code…
NOTE: If it didn’t work try do the restart once again from step 1, it will work.
Please use the latest TF version in colab with the below command –
!pip install tensorflow-text==2.13.0
Please restart the runtime post executing the command
I have problem with importing tensorflow_text
I tried importing like below two methods but none of them worked
import tensorflow_text as text
import tensorflow_text as tf_text
My tensorflow version is 2.9.1
and python version is Python 3.7.13
. I tried installing tensorflow_text
using below two methods but none of them is working.
!pip install tensorflow-text
!pip install -U tensorflow-text==2.9.0
I am using colab, I also tried reinstalling tensorflow but it still generates below error.
NotFoundError:
/usr/local/lib/python3.7/distpackages/tensorflow_text/python/ops/_sentencepiece_tokenizer.so:
undefined symbol: _ZNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEEC1Ev
Update, Sometimes you need to reinstall and update tensorflow
then install tensorflow_text
. (Because you need your tensorflow.__version__
and tensorflow_text.__version__
to have the same version)
!pip install -U tensorflow
!pip install -U tensorflow-text
import tensorflow as tf
import tensorflow_text as text
# Or install with a specific Version
!pip install -U "tensorflow==2.8.*"
!pip install -U "tensorflow-text==2.8.*"
import tensorflow as tf
import tensorflow_text as text
Old First, install tensorflow-text
version 2.8.*
like below:
!pip install -q -U "tensorflow-text==2.8.*"
Then import tensorflow-text
like below:
import tensorflow_text as text
I have tried I’mahdi’s answer and it was not working, but the following solution worked for me.
Here are the steps that solved it for me.
- Visit the Tensorflow-Text official site (https://www.tensorflow.org/text)
- There is a little scroll bar down the right side RUN IN COLAB NOTEBBOK you will see, click on it (else use this link https://colab.research.google.com/github/tensorflow/text/blob/master/docs/guide/bert_preprocessing_guide.ipynb)
- In this notebook, change runtime to GPU and RUN cell by cell until the setup section
- And then it will work (WAIT)
- Delete all other cells except 1st 2 cells of Setup section
- Then continue your code…
NOTE: If it didn’t work try do the restart once again from step 1, it will work.
Please use the latest TF version in colab with the below command –
!pip install tensorflow-text==2.13.0
Please restart the runtime post executing the command