简体   繁体   English

Tensorflow:模块'tensorflow'没有属性'constant'

[英]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. 我曾试图安装Tensorflow按照在Ubuntu 18.04 这个从Tensorflow网站安装指南。 However, after importing tensorflow in python/jupyter notebook, none of the functionality appears to be working. 但是,在python / jupyter笔记本中导入tensorflow后,所有功能似乎均不起作用。

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. 在tensorflow网站上,它仍然应该是功能齐全的命令。

This is my first time attempting to run tensorflow so any help on the topic would be greatly appreciated! 这是我第一次尝试运行tensorflow,因此非常感谢您对该主题的任何帮助!

You have to change your folder name to something else except tensorflow . 您必须将文件夹名称更改为tensorflow以外的其他名称。

The reason is when you use import x python first searches for a folder named x and imports __init__.py file inside it. 原因是当您使用import x python时,首先搜索一个名为x的文件夹,然后在其中导入__init__.py文件。 In your case you don't have that file with predefined constant in it and above that you want the tensorflow itself! 在您的情况下,您将没有带有预定义constant文件,并且在该文件之上还没有想要tensorflow的文件!

I had the same error. 我有同样的错误。 After I installed tensorflow-eigen the problem is solved. 我安装了tensorflow-eigen ,问题就解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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