ImportError:无法导入名称'regex_replace'

时间:2019-03-25 01:50:06

标签: python tensorflow-hub

我是python的新手,在运行程序时出现错误。

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/tensorflow_hub/tf_v1.py", line 29, in <module>
    from tensorflow.compat.v1 import *  
ImportError: No module named 'tensorflow.compat'

During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "train.py", line 5, in <module>
        import tensorflow_hub as hub
      File "/usr/local/lib/python3.5/dist-packages/tensorflow_hub/__init__.py", line 30, in <module>
        from tensorflow_hub.estimator import LatestModuleExporter
      File "/usr/local/lib/python3.5/dist-packages/tensorflow_hub/estimator.py", line 25, in <module>
        from tensorflow_hub import tf_utils
      File "/usr/local/lib/python3.5/dist-packages/tensorflow_hub/tf_utils.py", line 28, in <module>
        from tensorflow_hub import tf_v1
      File "/usr/local/lib/python3.5/dist-packages/tensorflow_hub/tf_v1.py", line 63, in <module>
        from tensorflow import regex_replace
    ImportError: cannot import name 'regex_replace'

我的train.py

import os
import numpy as np
import pandas as pd
import tensorflow as tf
import tensorflow_hub as hub
import json
import pickle
import urllib

from sklearn.preprocessing import LabelBinarizer

print(tf.__version__)

不导入tensorflow_hub即可正常工作..但是对于我的算法来说,它必须..我搜索了很多链接,但无法获得正确的解决方案。请给我一些小提示以解决我的问题。

1 个答案:

答案 0 :(得分:3)

尝试升级tensorflow模块。它为我工作。 使用以下命令进行升级。
pip install --upgrade tensorflow