Ask questionsAttributeError: module 'tensorflow' has no attribute 'gfile'


I am trying to load a file using the following code below. However, whenever I run my code I get an error stating that AttributeError: module 'tensorflow' has no attribute 'gfile' . I have successfully installed gin using pip install gin-config.

import tensorflow as tf

def load_directory_data(directory):
  data = {}
  data["sentence"] = []
  data["sentiment"] = []
  for file_path in os.listdir(directory):
    with, file_path), "r") as f:
      data["sentiment"].append(re.match("\d+_(\d+)\.txt", file_path).group(1))
  return pd.DataFrame.from_dict(data)

I've even done import , but when I run my code I then get...

` File "C:\Users\WTC\Anaconda3\lib\site-packages\bert\", line 125, in load_vocab with tf.gfile.GFile(vocab_file, "r") as reader:

AttributeError: module 'tensorflow' has no attribute 'gfile'`

Any thoughts as to why?


Answer questions Gurubux

Tensor-flow Version - 2.0.0-alpha0

Same error occurred while running a notebook from the Tensorflow site - Build a linear model with Estimators <br> Download the dataset:

from official.wide_deep import census_dataset
from official.wide_deep import census_main"/tmp/census_data/")

AttributeError Traceback (most recent call last) <ipython-input-9-fa1d43ace000> in <module>() 2 from official.wide_deep import census_main 3 ----> 4"/tmp/census_data/")

/content/models/official/wide_deep/ in download(data_dir) 76 def download(data_dir): 77 """Download census data if it is not already present.""" ---> 78 tf.gfile.MakeDirs(data_dir) 79 80 training_file_path = os.path.join(data_dir, TRAINING_FILE)

AttributeError: module 'tensorflow' has no attribute 'gfile' <hr>

The document suggests the following changes in the file.

Should I go about making the following changes manually in the file ?

WARNING: Logging before flag parsing goes to stderr. W0625 16:04:36.412110 139807458662144] From /tmpfs/src/temp/site/en/tutorials/estimators/models/official/wide_deep/ The name tf.gfile.MakeDirs is deprecated. Please use instead.

W0625 16:04:36.413802 139807458662144] From /tmpfs/src/temp/site/en/tutorials/estimators/models/official/wide_deep/ The name tf.gfile.Exists is deprecated. Please use instead.

W0625 16:04:38.253764 139807458662144] From /tmpfs/src/temp/site/en/tutorials/estimators/models/official/wide_deep/ The name tf.gfile.Open is deprecated. Please use instead.

W0625 16:04:38.488776 139807458662144] From /tmpfs/src/temp/site/en/tutorials/estimators/models/official/wide_deep/ The name tf.gfile.Remove is deprecated. Please use instead.

# #

Gurubux Gurubux India Computer Engineer B.E | Software Developer | Machine Learning Aspirant
Github User Rank List