Runtime environment: Anaconda’s virtual environment
A lot of people say this is because of the CUDA version, but I’ve found that another reason is the Python version of TensorFlow. If you look at the picture, TensorFlow at this point is Python 2.7.
So when I’m using Python 2.7, I don’t get anything wrong

I got an error when I imported TensorFlow in Python 3.6

Use the Conda List to see the Python version

I found that the default version of Python is 2.7. I created this virtual environment with 3.6, but for some reason it changed to 2.7.
The solution. Re-create the Conda environment and re-install TensorFlow.
A lot of people say this is because of the CUDA version, but I’ve found that another reason is the Python version of TensorFlow. If you look at the picture, TensorFlow at this point is Python 2.7.

So when I’m using Python 2.7, I don’t get anything wrong

I got an error when I imported TensorFlow in Python 3.6

Use the Conda List to see the Python version

I found that the default version of Python is 2.7. I created this virtual environment with 3.6, but for some reason it changed to 2.7.
The solution. Re-create the Conda environment and re-install TensorFlow.
conda create --name tensorflow python=3.6
conda install tensorflow
conda install tensorflow-gpu
conda list
Once installed, you will notice that TensorFlow is now Python 3.6.
Look at the default Python version
Is 3.6. The TensorFlow version corresponds to the Python version, so it should work fine.
As for why the Python version of the Anaconda virtual environment changed, I’m not sure.
Read More:
- The PIP installation package was successful but the import failed
- ModuleNotFoundError: No module named ‘tensorflow.python’ And the pits encountered after installation
- Tensorflow import Error: ImportError: libcuda.so.1: cannot open shared object file: No such file or dire
- Python3 Error: Cannot uninstall ‘numpy’. It is a distutils installed project and thus we cannot accurate
- error: Unable to find vcvarsall.bat
- [How to Fix]RuntimeError: Python is not installed as a framework, If you are using (Ana)Conda
- Using Python error urlopen error unknown URL type: the solution of HTTPS
- How to Fix Errors encountered in executing Python scripts with command line parameters
- About the solution of ERROR: Failed building wheel for dlib
- Pytorch: How to Handle error warning conda.gateways.disk.delete:unlink_or_rename_to_trash(140)
- Python exports the gitlab project
- When sending HTTP request, python encountered: error 54, ‘connection reset by peer’ solution
- Change the Python installation path in Pycharm
- npm install Error: stack Error: Can’t find Python executable “python”
- Python RarFile unpack RAR package Error Rarfile.RarCannotExec: Cannot find Working Tool
- How to Fix keyerror in Python dictionary lookup
- Importerror: DLL load failed: unable to find the specified module in Python
- Python syntax error except exception, e: ^ syntax error: invalid syntax
- Docker run xxx,E Time Elapsed: 0:00:00.000180
- Python 3 uses the relative path import module