简体   繁体   English

ModuleNotFoundError:没有名为“tensorflow.python”的模块 Anaconda

[英]ModuleNotFoundError: No module named 'tensorflow.python' Anaconda

I have been using Tensorflow on Anaconda for a while now, but recently I have been getting the mentioned error when trying to import Tensorflow.我在 Anaconda 上使用 Tensorflow 已经有一段时间了,但最近我在尝试导入 Tensorflow 时遇到了上述错误。

This has been asked here multiple times, so I tried suggested solutions but nothing worked so far (reinstalling tensorflow (both normal and gpu versions), reinstalling Anaconda).这已被多次询问,所以我尝试了建议的解决方案,但到目前为止没有任何效果(重新安装 tensorflow(普通版和 gpu 版),重新安装 Anaconda)。 When running help('modules') tensorflow appears in module list.运行help('modules')时,tensorflow 出现在模块列表中。 But even after I run pip uninstall tensorflow and pip uninstall tensorflow-gpu tensorflow still remains in module list when running help('modules') .但即使在我运行pip uninstall tensorflowpip uninstall tensorflow-gpu tensorflow 在运行help('modules')时仍然保留在模块列表中。

What can I do to fix this?我该怎么做才能解决这个问题?

Apparently the reason was the Python version (which is strange as according to documentation Tensorflow supports Python 3.7).显然,原因是 Python 版本(根据文档 Tensorflow 支持 Python 3.7,这很奇怪)。 I downgraded to 3.6 and I am able to import Tensorflow again我降级到 3.6,我可以再次导入 Tensorflow

As one of the solutions always would to manually delete TensorFlow package and then reinstall it.作为解决方案之一,总是会手动删除 TensorFlow 包,然后重新安装它。

sudo rm -rf /usr/local/pip/python3.6/dist-packages/tensorflow

Even when you uninstall tensorflow using pip, with help('modules') command, if tensorflow is still there, this might be because the packages are not accessed by python from the path "/usr/local/pip/python3.6" but rather from the path "/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages".即使当您使用 pip 卸载 tensorflow 时,使用 help('modules') 命令,如果 tensorflow 仍然存在,这可能是因为 python 无法从路径“/usr/local/pip/python3.6”访问这些包,但是而不是来自路径“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages”。

So to uninstall tensorflow from here, try:因此,要从此处卸载 tensorflow,请尝试:

conda remove tensorflow

or:要么:

conda remove -n your_env_name tensorflow

Once you do that install tensorflow using:一旦你这样做安装tensorflow使用:

 conda install -c conda-forge tensorflow 

Hopefully this will work.希望这会奏效。

Even if this does not work, then use rm to delete the tensorlflow package folder.即使这不起作用,然后使用 rm 删除 tensorlflow 包文件夹。

To do this do not assume that it will be present in the "/usr/local/pip/python3.6" path.为此,不要假设它会出现在“/usr/local/pip/python3.6”路径中。 But instead type:而是输入:

pip show tensorflow

This will give the path from which the tensorflow module is being imported by python.这将给出 python 导入 tensorflow 模块的路径。

Then run:然后运行:

rm -rf path-you-got-from-pip-show-tensorflow

暂无
暂无

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

相关问题 tensorflow:ModuleNotFoundError:没有名为“tensorflow.python.tools”的模块; 'tensorflow.python' 不是 package - tensorflow : ModuleNotFoundError: No module named 'tensorflow.python.tools'; 'tensorflow.python' is not a package ModuleNotFoundError:在蟒蛇python 3.6.3中没有名为'tensorflow'的模块 - ModuleNotFoundError: No module named ‘tensorflow’ in anaconda python 3.6.3 导入错误:没有名为“tensorflow.python”的模块 - ImportError: No module named 'tensorflow.python' Anaconda:ModuleNotFoundError:没有名为“tensorflow”的模块 - Anaconda : ModuleNotFoundError: No module named 'tensorflow' ModuleNotFoundError:anaconda 中没有名为“tensorflow”的模块 - ModuleNotFoundError: No module named 'tensorflow' in anaconda 没有名为“tensorflow.python.tools”的模块; “tensorflow.python”不是一个包 - No module named 'tensorflow.python.tools'; 'tensorflow.python' is not a package ImportError:没有带有tensorflow-gpu的名为'tensorflow.python'的模块 - ImportError: No module named 'tensorflow.python' with tensorflow-gpu 导入错误:没有名为“tensorflow.python”的模块; 'tensorflow' 不是一个包 - ImportError: No module named 'tensorflow.python'; 'tensorflow' is not a package Anaconda Python:ModuleNotFoundError:没有名为“matlab”的模块 - Anaconda Python: ModuleNotFoundError: No module named 'matlab' tensorflow 在 anaconda 控制台中工作,在笔记本中失败:.ModuleNotFoundError: No module named 'tensorflow' - tensorflow works in anaconda console, fails in notebook with:.ModuleNotFoundError: No module named 'tensorflow'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM