无法导入tensorflow_text

alb*_*ert 5 python tensorflow tensorflow2.0

我在导入时遇到问题tensorflow_text我尝试像下面的两种方法一样导入,但没有一个起作用

import tensorflow_text as text
import tensorflow_text as tf_text
Run Code Online (Sandbox Code Playgroud)

我的tensorflow版本是2.9.1,python版本是Python 3.7.13。我尝试tensorflow_text使用以下两种方法进行安装,但它们都不起作用。

!pip install tensorflow-text
!pip install -U tensorflow-text==2.9.0
Run Code Online (Sandbox Code Playgroud)

我正在使用 colab,我也尝试重新安装tensorflow,但它仍然生成以下错误。

NotFoundError: 
/usr/local/lib/python3.7/distpackages/tensorflow_text/python/ops/_sentencepiece_tokenizer.so: 
undefined symbol: _ZNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEEC1Ev
Run Code Online (Sandbox Code Playgroud)

I'm*_*hdi 4

更新,有时需要重新安装更新tensorflow然后安装tensorflow_text(因为你需要你的tensorflow.__version__tensorflow_text.__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
Run Code Online (Sandbox Code Playgroud)

旧的首先,安装如下tensorflow-text版本:2.8.*

!pip install -q -U "tensorflow-text==2.8.*"
Run Code Online (Sandbox Code Playgroud)

然后像下面这样导入tensorflow-text

import tensorflow_text as text 
Run Code Online (Sandbox Code Playgroud)