Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'tuple' object has no attribute 'type' upon importing tensorflow

I installed the Tensorflow(-gpu) version 1.8.0 as a pip package following these instructions. Upon installation, I opened a python3 console and typed in

import tensorflow as tf

Upon which,I get the following error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/px2/.local/lib/python3.5/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "/home/px2/.local/lib/python3.5/site-packages/tensorflow/python/__init__.py", line 47, in <module>
    import numpy as np
  File "/home/px2/.local/lib/python3.5/site-packages/numpy/__init__.py", line 142, in <module>
    from . import core
  File "/home/px2/.local/lib/python3.5/site-packages/numpy/core/__init__.py", line 57, in <module>
    from . import numerictypes as nt
  File "/home/px2/.local/lib/python3.5/site-packages/numpy/core/numerictypes.py", line 111, in <module>
    from ._type_aliases import (
  File "/home/px2/.local/lib/python3.5/site-packages/numpy/core/_type_aliases.py", line 63, in <module>
    _concrete_types = {v.type for k, v in _concrete_typeinfo.items()}
  File "/home/px2/.local/lib/python3.5/site-packages/numpy/core/_type_aliases.py", line 63, in <setcomp>
    _concrete_types = {v.type for k, v in _concrete_typeinfo.items()}
AttributeError: 'tuple' object has no attribute 'type'

A similar looking problem reported on StackOverflow has an answer that versions > 1.7 seems to not have this problem. But I seem to have it in 1.8

Can someone help me out?

like image 843
dhas Avatar asked Jan 15 '19 14:01

dhas


2 Answers

In fact, this means you have multiple versions of numpy installed somehow (or there are multiple versions that are overlapping). You need to make sure that numpy is fully uninstalled from your system, then reinstall.

For me, I did

pip uninstall numpy
sudo apt-get purge python3-numpy

Then I had to go to /usr/local/lib/python3.6/dist-packages and delete the numpy folders that were still there for some reason. After that, reinstalling numpy with

pip install numpy

worked. Here is the github issue I opened on it:

https://github.com/numpy/numpy/issues/12775

like image 94
wordsforthewise Avatar answered Nov 15 '22 06:11

wordsforthewise


Had the same issue, fixed by going back to Numpy 1.15.4 Thanks wordsforthewise

like image 23
Sylvain Avatar answered Nov 15 '22 08:11

Sylvain