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.
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). When running help('modules')
tensorflow appears in module list. But even after I run pip uninstall tensorflow
and pip uninstall tensorflow-gpu
tensorflow still remains in module list when running 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). I downgraded to 3.6 and I am able to import Tensorflow again
As one of the solutions always would to manually delete TensorFlow package and then reinstall it.
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".
So to uninstall tensorflow from here, try:
conda remove tensorflow
or:
conda remove -n your_env_name tensorflow
Once you do that install tensorflow using:
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.
To do this do not assume that it will be present in the "/usr/local/pip/python3.6" path. But instead type:
pip show tensorflow
This will give the path from which the tensorflow module is being imported by python.
Then run:
rm -rf path-you-got-from-pip-show-tensorflow
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.