
[英]tensorflow : ModuleNotFoundError: No module named 'tensorflow.python.tools'; 'tensorflow.python' is not a package
[英]ModuleNotFoundError: No module named 'tensorflow.python' Anaconda
我在 Anaconda 上使用 Tensorflow 已经有一段时间了,但最近我在尝试导入 Tensorflow 时遇到了上述错误。
这已被多次询问,所以我尝试了建议的解决方案,但到目前为止没有任何效果(重新安装 tensorflow(普通版和 gpu 版),重新安装 Anaconda)。 运行help('modules')
时,tensorflow 出现在模块列表中。 但即使在我运行pip uninstall tensorflow
和pip uninstall tensorflow-gpu
tensorflow 在运行help('modules')
时仍然保留在模块列表中。
我该怎么做才能解决这个问题?
显然,原因是 Python 版本(根据文档 Tensorflow 支持 Python 3.7,这很奇怪)。 我降级到 3.6,我可以再次导入 Tensorflow
作为解决方案之一,总是会手动删除 TensorFlow 包,然后重新安装它。
sudo rm -rf /usr/local/pip/python3.6/dist-packages/tensorflow
即使当您使用 pip 卸载 tensorflow 时,使用 help('modules') 命令,如果 tensorflow 仍然存在,这可能是因为 python 无法从路径“/usr/local/pip/python3.6”访问这些包,但是而不是来自路径“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages”。
因此,要从此处卸载 tensorflow,请尝试:
conda remove tensorflow
要么:
conda remove -n your_env_name tensorflow
一旦你这样做安装tensorflow使用:
conda install -c conda-forge tensorflow
希望这会奏效。
即使这不起作用,然后使用 rm 删除 tensorlflow 包文件夹。
为此,不要假设它会出现在“/usr/local/pip/python3.6”路径中。 而是输入:
pip show tensorflow
这将给出 python 导入 tensorflow 模块的路径。
然后运行:
rm -rf path-you-got-from-pip-show-tensorflow
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.