简体   繁体   中英

Tensorflow: module 'tensorflow' has no attribute 'constant'

I have attempted to install Tensorflow on Ubuntu 18.04 by following this installation guide from the Tensorflow website. However, after importing tensorflow in python/jupyter notebook, none of the functionality appears to be working.

For example if I run:

#import tensorflow
import tensorflow as tf

#initialize two constants
x1 = tf.constant([1,2,3,4])
x2 = tf.constant([5,6,7,8])

I get the following error:

AttributeError: module 'tensorflow' has no attribute 'constant'

Does anyone know why this attribute is unavailable? on the tensorflow website it should be still be a fully functional command.

This is my first time attempting to run tensorflow so any help on the topic would be greatly appreciated!

You have to change your folder name to something else except tensorflow .

The reason is when you use import x python first searches for a folder named x and imports __init__.py file inside it. In your case you don't have that file with predefined constant in it and above that you want the tensorflow itself!

I had the same error. After I installed tensorflow-eigen the problem is solved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM