python - AttributeError:模块“tensorflow”没有属性“常量”
问题描述
最近我在我的机器上安装了 tensorflow(CPU)。后来,我决定通过安装 tensorflow-gpu 来选择 GPU 版本。所以我先卸载了非gpu版本,然后按照tensorflow官网的步骤安装了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'
解决方案
推荐阅读
- java - 为什么 List.contains(Object) 的行为不同?
- r - 如何在同一个数据帧上做colsum和average
- powerbi - 使用 DAX 生成日期系列
- javascript - 仅在服务器上需要一个包
- java - Intellij IDEA 仅针对所有未提交的更改运行测试
- regex - 在换行符之前匹配字符,不包括空格?
- macos - MacOS - 使用带有launchd的脚本 - 启动,登录,注销,关闭?
- service-worker - Workbox 的服务人员在更改时未更新
- python - AllenNLP 共指分辨率的多 GPU 训练
- reactjs - 事件处理程序中带有 [name] 的 PrevState