Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'module' object has no attribute 'constant' #3369

Closed
k3nnywilliam opened this issue Jul 18, 2016 · 16 comments
Closed

AttributeError: 'module' object has no attribute 'constant' #3369

k3nnywilliam opened this issue Jul 18, 2016 · 16 comments

Comments

@k3nnywilliam
Copy link

Hi everyone, I tried to run Tensorflow 0.9.0 with Python 3.4 but I've received this error:

Python 3.4.5 |Continuum Analytics, Inc.| (default, Jul 2 2016, 17:47:57)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'module' object has no attribute 'constant'

Steps to reproduce

  1. Installed Anaconda 64-bit Python 3.5
  2. Installed Tensorflow following these instructions

What have you tried?

Tried with Python 3.5 but no luck as well. Version 2.7 works fine but I need to use version 3.x as part of my coursework requirement.

Environment info

Operating System: OSX 10.11.1

@dstu
Copy link

dstu commented Jul 21, 2016

I'm also running into this problem, after having followed the instructions for installing TensorFlow via pip on www.tensorflow.org, under Python 3.5.2 in Debian unstable. Here's what dir(tf) says after I import tensorflow as tf:

['__doc__', '__loader__', '__name__', '__package__', '__path__', '__spec__']

help(tf) is similarly unhelpful, giving some simple boilerplate and nothing else.

Edit: I note that I mistakenly installed TensorFlow for GPU processing, using the URL with /gpu/ in it. I do not have CUDA toolkit or CuDNN installed. But uninstalling TensorFlow and installing it from the correct URL has not gotten things working.

@concretevitamin
Copy link
Contributor

I just tried to follow the Anaconda 64-bit Python 3.4 on my Ubuntu, and it worked fine. One thing to check: if you used sudo in the installation process, directly launching python3 might fail to find tensorflow; instead try sudo python3.

Did you use the GPU version or CPU-only version?

@concretevitamin concretevitamin added the stat:awaiting response Status - Awaiting response from author label Jul 21, 2016
@dstu
Copy link

dstu commented Jul 21, 2016

sudo python3 gives me a full tensorflow module. See my edit about RE the CPU version vs. the GPU version.

It looks like /usr/local/lib/python3.5/dist-packages/tensorflow/ is set drwxr-S--- for some bizarre reason. This might not be a problem with your packaging; if I install another third-party module (like flask) using pip3 install, I also have problems viewing its contents as a non-root user. I'll try using a virtualenv, instead.

@dstu
Copy link

dstu commented Jul 21, 2016

Actually, as per http://caligari.treboada.net/2014/09/23/python-pip-and-the-staff-group/, it should be sufficient to add your user to the group staff and then install with pip/pip3 install (rather than sudo pip/pip3).

@k3nnywilliam
Copy link
Author

Since I'm using OSX, the binary provided is CPU-only therefore I'm not having any problem with GPU vs CPU version.

Ok, so far I got python 3.5 working by installing TF via pip. Which means it has something to do with the conda package manager maybe...? It works with python 2.7 so I'm not sure. Tried sudo python3, nothing worked.

@aselle aselle removed the stat:awaiting response Status - Awaiting response from author label Jul 21, 2016
@concretevitamin
Copy link
Contributor

Looks like it has been workaround-ed. Closing for now.

@victoriastuart
Copy link

In case this helps others:

Related: I had an issue (tensorflow 0.9), in that scripts stopped working: " AttributeError: 'module' object has no attribute 'constant' ". Thanks to this answer [http://stackoverflow.com/questions/37383812/tensorflow-module-object-has-no-attribute-placeholder], I looked and noticed that I had a folder named "tensorflow". I renamed that folder, and my scripts are working again.

@tahirahmad2030
Copy link

In my case i had named the file as "tensorflow.py" which was the cause of above Error. I changed the file name which fixed the problem. Also deleted mt script file "tensorflow.py".

@gallybaba
Copy link

i have the same issue and I am not using a file name and nor am i under a source tree. problem goes away if i install tensorflow-gpu but comes back when i install native build from source using bazel. I also notice that https://www.tensorflow.org/install/install_linux#InstallingAnaconda had a LOT more files than local pip package create from bazel.
I have ubuntu 16 xenial with nvidia ge force 780i. I built local pip package following https://www.tensorflow.org/install/install_sources
i have python as anaconda3.

issue
python
Python 3.6.0 |Anaconda 4.3.1 (64-bit)| (default, Dec 23 2016, 12:22:00)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.

import tensorflow as tf
hello = tf.constant("Hello, TensorFlow!")
Traceback (most recent call last):
File "", line 1, in
AttributeError: module 'tensorflow' has no attribute 'constant'
hello = tf.constant('Hello, TensorFlow!')
Traceback (most recent call last):
File "", line 1, in
AttributeError: module 'tensorflow' has no attribute 'constant'

The directory permissions look ok as well where this package was distributed. Am i missing something?

@Reasoning-Technology
Copy link

Reasoning-Technology commented Aug 2, 2017

Same thing. Simple direct install.

2017-08-02T07:02:19Z

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 17.04
Release:	17.04
Codename:	zesty

$ sudo su -l

# pip3 install tensorflow
      Collecting tensorflow
 Downloading tensorflow-1.2.1-cp35-cp35m-manylinux1_x86_64.whl (34.5MB)
   100% |████████████████████████████████| 34.5MB 45kB/s 
Requirement already satisfied: six>=1.10.0 in /usr/lib/python3/dist-packages (from tensorflow)
Collecting backports.weakref==1.0rc1 (from tensorflow)
 Downloading backports.weakref-1.0rc1-py3-none-any.whl
Collecting numpy>=1.11.0 (from tensorflow)
 Downloading numpy-1.13.1-cp35-cp35m-manylinux1_x86_64.whl (16.9MB)
   100% |████████████████████████████████| 16.9MB 91kB/s 
Collecting werkzeug>=0.11.10 (from tensorflow)
 Downloading Werkzeug-0.12.2-py2.py3-none-any.whl (312kB)
   100% |████████████████████████████████| 317kB 2.2MB/s 
Requirement already satisfied: wheel>=0.26 in /usr/lib/python3/dist-packages (from tensorflow)
Collecting protobuf>=3.2.0 (from tensorflow)
 Downloading protobuf-3.3.0-cp35-cp35m-manylinux1_x86_64.whl (5.7MB)
   100% |████████████████████████████████| 5.7MB 258kB/s 
Collecting html5lib==0.9999999 (from tensorflow)
 Downloading html5lib-0.9999999.tar.gz (889kB)
   100% |████████████████████████████████| 890kB 1.2MB/s 
Collecting bleach==1.5.0 (from tensorflow)
 Downloading bleach-1.5.0-py2.py3-none-any.whl
Collecting markdown>=2.6.8 (from tensorflow)
 Downloading Markdown-2.6.8.tar.gz (307kB)
   100% |████████████████████████████████| 317kB 2.8MB/s 
Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (from protobuf>=3.2.0->tensorflow)
Building wheels for collected packages: html5lib, markdown
 Running setup.py bdist_wheel for html5lib ... done
 Stored in directory: /root/.cache/pip/wheels/6f/85/6c/56b8e1292c6214c4eb73b9dda50f53e8e977bf65989373c962
 Running setup.py bdist_wheel for markdown ... done
 Stored in directory: /root/.cache/pip/wheels/85/a7/08/33ee5cd488d0365d8bed79d1d4e5c28dd3fbfc7f6d0ad4bb09
Successfully built html5lib markdown
Installing collected packages: backports.weakref, numpy, werkzeug, protobuf, html5lib, bleach, markdown, tensorflow
 Found existing installation: html5lib 0.999999999
   Not uninstalling html5lib at /usr/lib/python3/dist-packages, outside environment /usr
Successfully installed backports.weakref-1.0rc1 bleach-1.5.0 html5lib-0.9999999 markdown-2.6.8 numpy-1.13.1 protobuf-3.3.0 tensorflow-1.2.1 werkzeug-0.12.2

^d
$ Python 3.5.3 (default, Jan 19 2017, 14:11:04) 
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> python.el: native completion setup loaded
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow' has no attribute 'constant'

as that didn't work, I went back and did the optional step 2, getting the storage file from the link as suggested:

# pip3 install tensoflow --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.2.1-cp35-cp35m-linux_x86_64.whl
Collecting tensoflow
  Could not find a version that satisfies the requirement tensoflow (from versions: )
No matching distribution found for tensoflow

So what does this mean? Is Tensorflow installed? How should I proceed??

@kmaher9
Copy link

kmaher9 commented Aug 2, 2017

@antigonus, you're misspelling the command. You have tensoflow instead of tensorflow.

It should be;
sudo pip3 install tensorflow --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.2.1-cp35-cp35m-linux_x86_64.whl

If you get another, similar error, attempt to install from a different package.

sudo pip3 install tensorflow --upgrade install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.2.1-cp35-cp35m-manylinux1_x86_64.whl

@Reasoning-Technology
Copy link

Reasoning-Technology commented Aug 3, 2017

@faullath, thank you! I suspect the first problem was something about permissions having run pip3 as root. (Other posts have noted such problems with pip3.) That misspelling is incredible as that command was cut and paste from the dialog to the shell then to here. Somehow a character was deleted, or wasn't there in the first place. I didn't think to examine it closely. I ended up replacing Ubuntu 17 with a Debian Stretch, ran pip3 as a user on the new system using a direct install by the first step (not the optional 2nd step), and everything went smoothly.

@wednesy
Copy link

wednesy commented Oct 17, 2017

After directly installing with pip3 install tensorflow, I am struggling with the same problem.

@Brenndoerfer
Copy link

Brenndoerfer commented Oct 21, 2017

Run into the same error.
Reason: File was named logging.py
Solution: Rename file

@kmnis
Copy link

kmnis commented Feb 26, 2018

I installed tensorflow from Source had the same problem. I noticed that while executing the command "sudo pip install /tmp/tensorflow_pkg/tensorflow-1.5.0-py2-none-any.whl", I was executing it by copying and pasting it directly which was wrong because the term "tensorflow-1.5.0-py2-none-any.whl" need to be replaced with the right name of the .whl file. First time running it gave some error but when I ran it again, it worked like a charm. You can find it in location /tmp/tensorflow_pkg. Just putting it here hoping it would save someone else's load of time.

@ujur007
Copy link

ujur007 commented Jul 16, 2018

@concretevitamin sudo python helps!!

I had an error

python
Python 2.7.15 |Anaconda, Inc.| (default, May 1 2018, 23:32:55)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import tensorflow
Traceback (most recent call last):
File "", line 1, in
File "/home/ujjval/anaconda2/lib/python2.7/site-packages/tensorflow/init.py", line 22, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/home/ujjval/anaconda2/lib/python2.7/site-packages/tensorflow/python/init.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "/home/ujjval/anaconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/home/ujjval/anaconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/ujjval/anaconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/ujjval/anaconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory

Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests