How to fix "module 'tensorflow' has no attribute 'estimator' " error
Asked Answered
C

5

11

I'm using conda (env created via YAML) + pip to set up a Tensorflow v1.13.1 environment on my Linux Mint box. After setup, whenever I try to import tf.estimator I receive the AttributeError described in the title:

AttributeError: module 'tensorflow' has no attribute 'estimator'
  • I do not have any version of TF installed outside of a conda environment (or on pip).
  • I do have another conda environment set up the same way but with Tensorflow 2.0 alpha, which can import tf.estimator just fine.
  • I have tried removing the environment and building it again
  • I have tried rebooting :(
  • For some reason I cannot update conda to 4.6:
$ conda update -n base -c defaults conda

# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<

    Traceback (most recent call last):
      File "/usr/share/anaconda3/lib/python3.7/site-packages/conda/exceptions.py", line 819, in __call__
        return func(*args, **kwargs)
      File "/usr/share/anaconda3/lib/python3.7/site-packages/conda/cli/main.py", line 78, in _main
        exit_code = do_call(args, p)
      File "/usr/share/anaconda3/lib/python3.7/site-packages/conda/cli/conda_argparse.py", line 77, in do_call
        exit_code = getattr(module, func_name)(args, parser)
      File "/usr/share/anaconda3/lib/python3.7/site-packages/conda/cli/main_update.py", line 14, in execute
        install(args, parser, 'update')
      File "/usr/share/anaconda3/lib/python3.7/site-packages/conda/cli/install.py", line 253, in install
        handle_txn(unlink_link_transaction, prefix, args, newenv)
      File "/usr/share/anaconda3/lib/python3.7/site-packages/conda/cli/install.py", line 282, in handle_txn
        unlink_link_transaction.execute()
      File "/usr/share/anaconda3/lib/python3.7/site-packages/conda/core/link.py", line 223, in execute
        self.verify()
      File "/usr/share/anaconda3/lib/python3.7/site-packages/conda/common/io.py", line 46, in decorated
        return f(*args, **kwds)
      File "/usr/share/anaconda3/lib/python3.7/site-packages/conda/core/link.py", line 200, in verify
        self.prepare()
      File "/usr/share/anaconda3/lib/python3.7/site-packages/conda/core/link.py", line 192, in prepare
        stp.remove_specs, stp.update_specs)
      File "/usr/share/anaconda3/lib/python3.7/site-packages/conda/core/link.py", line 282, in _prepare
        mkdir_p(transaction_context['temp_dir'])
      File "/usr/share/anaconda3/lib/python3.7/site-packages/conda/gateways/disk/__init__.py", line 60, in mkdir_p
        makedirs(path)
      File "/usr/share/anaconda3/lib/python3.7/os.py", line 221, in makedirs
        mkdir(name, mode)
    PermissionError: [Errno 13] Permission denied: '/usr/share/anaconda3/.condatmp'

The yml file looks like this:

dependencies:
- python
- numpy
- tensorflow
- cudatoolkit==9.0
...

From inside the environment in question:

  • $ conda list tensorflow
    # packages in environment at /home/cjs/.conda/envs/my-env:
    # 
    # Name                    Version                   Build  Channel
    tensorflow                1.13.1          mkl_py37h54b294f_0
    tensorflow-base           1.13.1          mkl_py37h7ce6ba3_0
    tensorflow-estimator      1.13.0                     py_0
  • $ pip list | grep tensorflow
    tensorflow                  1.13.1
    tensorflow-estimator        1.13.0
  • $ which pip
    /home/cjs/.conda/envs/my-env/bin/pip
  • $ conda --version
    conda 4.5.11
  • $ pip --version
    pip 19.0.3 from /home/cjs/.local/lib/python3.7/site-packages/pip (python 3.7)

Here is a minimal example of the issue. As you can see, this only occurs where tf.estimator is called, all other Tensorflow attributes act as expected:

Python 3.7.3 (default, Mar 27 2019, 22:11:17)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.__version__
'1.13.1'
>>> tf.estimator
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow' has no attribute 'estimator'
>>> tf.estimator.Estimator()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow' has no attribute 'estimator'
>>> from tensorflow import estimator
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'estimator' from 'tensorflow' (/home/cjs/.conda/envs/my-env/lib/python3.7/site-packages/tensorflow/__init__.py)
>>> tf.Variable
<class 'tensorflow.python.ops.variables.VariableV1'>
>>> tf.keras
<module 'tensorflow._api.v1.keras' from '/home/cjs/.conda/envs/my-env/lib/python3.7/site-packages/tensorflow/_api/v1/keras/__init__.py'>
>>> tf.constant
<function constant_v1 at 0x7fb25ea24950>

UPDATE

As per https://docs.nvidia.com/deploy/cuda-compatibility/index.html#binary-compatibility__table-toolkit-driver I was able to figure out that my nvidia drivers and cudatoolkit versions were out of sync (390.46 vs 9.0).

I have now updated my NVIDIA drivers to v418, and was able to update my conda version to 4.16.14. I updated the environment.yml shown above to cudatoolkit==10.1, but I can't seem to figure out how to actually install that.

My numba -s output includes this section, which makes me think the whole issue from the beginning was that cuda isn't finding my GPU (or can't connect to it?).

__CUDA Information__
Error: CUDA device intialisation problem. Message:Error at driver init:
[100] Call to cuInit results in CUDA_ERROR_NO_DEVICE:
Error class: <class 'numba.cuda.cudadrv.error.CudaSupportError'>

(MINOR) UPDATE

Was able to determine the cause of the numba issue was that I did not reboot since updating the GPU drivers (duh).

Not completely out of the woods on that, though. New issue is the following:

__CUDA Information__
Found 1 CUDA devices
id 0          b'Quadro K620'                              [SUPPORTED]
                      compute capability: 5.0
                           pci device id: 0
                              pci bus id: 1
Summary:
        1/1 devices are supported
CUDA driver version                 : 10010
CUDA libraries:
Finding cublas
        ERROR: can't locate lib
Finding cusparse
        ERROR: can't locate lib
Finding cufft
        ERROR: can't locate lib
Finding curand
        ERROR: can't locate lib
Finding nvvm
        ERROR: can't locate lib
        finding libdevice for compute_20...     ERROR: can't open libdevice for compute_20
        finding libdevice for compute_30...     ERROR: can't open libdevice for compute_30
        finding libdevice for compute_35...     ERROR: can't open libdevice for compute_35
        finding libdevice for compute_50...     ERROR: can't open libdevice for compute_50
Constrict answered 19/4, 2019 at 13:38 Comment(8)
Can you write your code? the point where you try to import.Epigene
@Epigene it is anywhere I use it, even in the python interpreter when I do >>>import tensorflow as tf, then >>>tf.estimator it will produce the errorConstrict
Ok, but can you give us an example of how do you use it? import tf.estimator gives errors ?Epigene
Updated with a few examples of how I'm using it.Constrict
Still one doubt. You have written "/home/cjs/.conda/envs/my-env" and "/home/cjs/.conda/envs/delreo-env" was this intentional? or are you looking at 2 different envs?Epigene
No, I was just making the initial one generic. They both represent the same environment, sorry.Constrict
Updated my question with some more findings I've made.Constrict
I just installed a conda env on LUbuntu, with tensorflow 1.13.1, and it works with no problems. Can you please post the output of ls /home/cjs/.conda/envs/my-env/lib/python3.7/site-packages | grep tensorflow ? Also, I do not understand why NVIDIA should be related to this subject.Epigene
C
2

Finally found the issue. I had some local (non-Conda) Tensorflow packages still installed, which were higher priority in the python environment, I guess.

This link solved my issue: https://github.com/tensorflow/tensorboard/issues/2067

  • Uninstall tensorflow, tensorboard
  • Uninstall tb-nightly(if it is installed)
  • Use "pip freeze | grep tensorflow" to check if tensorflow-estimator package has been installed. If so, uninstall it.
  • Go to site-packages and remove all tensorflow folders related to tensorflow, tensorboard, tensorflow-estimator etc
  • Reinstall the latest versions of tensorflow and tensorboard

The key for my issue was the sitepackages, which can be found at BOTH

  • ~/.conda/envs/<my-env>/lib/python3.<xx>/site-packages
  • ~/.local/lib/python3.<xx>/site-packages

Where <my-env> is your conda environment and <xx> is your python version.

Just rm -r <path to package> each tensorflow package in your ~/.local/ library and reinstall the conda environment.

Constrict answered 30/4, 2019 at 20:13 Comment(0)
H
1

Just uninstall tensorflow, tensorboard, and tensorflow-estimator and reinstall tensorflow. Worked for me with version 1.14.0.

pip uninstall tensorflow tensorboard tensorflow-estimator
...
pip install tensorflow==1.14.0
Hydrastinine answered 26/3, 2020 at 8:19 Comment(0)
J
0
  1. Uninstall tensorflow-estimator
  2. Reinstall it using pip install tensorflow-estimator==(same as your tf version 1.13.1)
Jackelinejackelyn answered 2/12, 2020 at 15:26 Comment(0)
I
0

This solution uses an up-to-date version of TensorFlow, yet the problem persists with the 2.16 version of Tensorflow which is using Keras instead of Estimator. The easy fix, if you are looking to keep using Estimator, is to uninstall both TensorFlow and TensorFlow Estimator and install the latest version of TensorFlow that supports it with:

pip3 install tensorflow==2.15

TensorFlow 2.15 includes the final release of the TensorFlow Estimator package.

Inequitable answered 11/4 at 20:50 Comment(0)
C
-1

Done:

I had some local (non-Conda) tensorflow packages still installed, which were higher priority in the python environment

in your

cd ~/.local
rm -r <tensorflow_package_libraries>

remove each tensorflow package library and reinstall the conda environment.

Canula answered 10/2, 2021 at 9:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.