AttributeError:模块“ tensorflow”没有属性“ constant”

时间:2018-07-02 06:36:02

标签: python windows tensorflow

最近我在机器上安装了tensorflow(CPU)。后来,我决定通过安装tensorflow-gpu来选择GPU版本。因此,我首先按照tensorflow官方网站上的步骤卸载了非gpu版本并安装了gpu版本。

问题是,当我尝试使用框架时,出现此错误

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

...在解释器中执行以下代码后:

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

为什么会发生这种情况?

注意:我尝试卸载tensorflow-gpu(以便再次安装),但出现此异常:

Exception:
Traceback (most recent call last):
File "c:\users\georgi koemdzhiv\appdata\local\programs\python\python3 \lib\shutil.py", line 544, in move os.rename(src, real_dst)
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'c:\\users\\georgi koemdzhiv\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\tensorflow\\contrib\\tensor_forest\\hybrid\\python\\models\\__pycache__\\stochastic_hard_decisions_to_data_then_nn.cpython-36.pyc' -> 'C:\\Users\\GEORGI~1\\AppData\\Local\\Temp\\pip-uninstall-tdr0yqcp\\users\\georgi koemdzhiv\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\tensorflow\\contrib\\tensor_forest\\hybrid\\python\\models\\__pycache__\\stochastic_hard_decisions_to_data_then_nn.cpython-36.pyc'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\users\georgi koemdzhiv\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\basecommand.py", line 228, in main
status = self.run(options, args)
File "c:\users\georgi koemdzhiv\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\commands\uninstall.py", line 68, in run
auto_confirm=options.yes, verbose=self.verbosity > 0,
File "c:\users\georgi koemdzhiv\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\req\req_install.py", line 661, in uninstall
uninstalled_pathset.remove(auto_confirm, verbose)
File "c:\users\georgi koemdzhiv\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\req\req_uninstall.py", line 219, in remove
renames(path, new_path)
File "c:\users\georgi koemdzhiv\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\utils\misc.py", line 273, in renames
shutil.move(old, new)
File "c:\users\georgi koemdzhiv\appdata\local\programs\python\python36\lib\shutil.py", line 558, in move
copy_function(src, real_dst)
File "c:\users\georgi koemdzhiv\appdata\local\programs\python\python36\lib\shutil.py", line 257, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "c:\users\georgi koemdzhiv\appdata\local\programs\python\python36\lib\shutil.py", line 121, in copyfile
with open(dst, 'wb') as fdst:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\GEORGI~1\\AppData\\Local\\Temp\\pip-uninstall-tdr0yqcp\\users\\georgi koemdzhiv\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\tensorflow\\contrib\\tensor_forest\\hybrid\\python\\models\\__pycache__\\stochastic_hard_decisions_to_data_then_nn.cpython-36.pyc'

0 个答案:

没有答案