'Keras installed through Conda breaks the Anaconda Prompt on Windows 10 [closed]

I have a Win10 OS, with Anaconda 3.6 installed, and a friend told me to install keras by using a specific conda command. Without reading any other documentation, i took his word for it. So, I originally performed the following command that he shared with me, in the anaconda prompt to install keras:

conda install -c conda-forge keras

The install did not complete and then the anaconda prompt quit unexpectedly.

Then when trying to launch anaconda prompt again, i got the following information and then it quits again after a second:

C:\Users\Aaron>python C:\Users\Aaron\Anaconda3\etc\keras\load_config.py  1>temp.txt

C:\Users\Aaron>set /p KERAS_BACKEND= 0<temp.txt

C:\Users\Aaron>del temp.txt

C:\Users\Aaron>python -c "import keras"  1>nul 2>&1

I couldn't find any solutions for fixing the problem here on stackoverflow. So, I examined the anaconda3 library bin files, and examined for any recently changed files, but I couldn't narrow it down, because one of the main config files was also changed, and it was too long and big of a file to go through to make sense of what changed.

So, i first tried to update all my anaconda files by doing the following:

conda update --all

No luck. I then tried to remove keras:

conda remove keras

still no luck. i finally uninstalled anaconda and registry remnants by using revo uninstaller with an advanced scan setting.

i then downloaded and ran the latest anaconda installer for windows 64 bit: https://repo.continuum.io/archive/Anaconda3-2018.12-Windows-x86_64.exe

I then installed Anaconda again, and now the problem has been fixed. Unfortunately, now i have to install a bunch of separate python libraries.

I then read the install documentation for keras, and it says that tensor flow needs to be installed first, so i did that by doing this in the Anaconda Prompt (after checking https://pypi.org/project/tensorflow/ ):

pip install tensorflow

i then got an error message:

(base) C:\Users\Aaron>pip install tensorflow
Collecting tensorflow
  Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow

and it said that the version was not supported, so i found out that the latest Anaconda version that i just installed, which was built with Python 3.7, and was not compatible with TensorFlow, which is limited to Python 3.6. So, I then created a python 3.6 virtual environment within conda, by doing:

conda create -n venv pip python=3.6

i then activated the virtual environment:

conda activate venv

then, within this virtual environment, i installed the tensorflow pip package that was supported with windows and python 3.6, by looking at the version list here: https://www.tensorflow.org/install/pip#package-location

So, i copied the link for the version developed for windows and python 3.6 (cpu only), which is:
https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.12.0-cp36-cp36m-win_amd64.whl

and then i added that url into the command to install it:

(venv) C:\Users\Aaron>pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.12.0-cp36-cp36m-win_amd64.whl

The install completed and installed some other stuff too:

Successfully installed absl-py-0.6.1 astor-0.7.1 gast-0.2.0 grpcio-1.17.1 h5py-2.9.0 keras-applications-1.0.6 keras-preprocessing-1.0.5 markdown-3.0.1 numpy-1.15.4 protobuf-3.6.1 setuptools-40.6.3 six-1.12.0 tensorboard-1.12.2 tensorflow-1.12.0 termcolor-1.1.0 werkzeug-0.14.1 wheel-0.32.3

I then read the Keras documentation from their website, and then I installed keras:

(venv) C:\Users\Aaron>pip install keras
Collecting keras
  Downloading https://files.pythonhosted.org/packages/5e/10/aa32dad071ce52b5502266b5c659451cfd6ffcbf14e6c8c4f16c0ff5aaab/Keras-2.2.4-py2.py3-none-any.whl (312kB)
    100% |████████████████████████████████| 317kB 2.6MB/s
Requirement already satisfied: numpy>=1.9.1 in c:\users\aaron\anaconda3\envs\venv\lib\site-packages (from keras) (1.15.4)
Requirement already satisfied: keras-applications>=1.0.6 in c:\users\aaron\anaconda3\envs\venv\lib\site-packages (from keras) (1.0.6)
Requirement already satisfied: h5py in c:\users\aaron\anaconda3\envs\venv\lib\site-packages (from keras) (2.9.0)
Collecting pyyaml (from keras)
  Downloading https://files.pythonhosted.org/packages/4f/ca/5fad249c5032270540c24d2189b0ddf1396aac49b0bdc548162edcf14131/PyYAML-3.13-cp36-cp36m-win_amd64.whl (206kB)
    100% |████████████████████████████████| 215kB 3.6MB/s
Requirement already satisfied: six>=1.9.0 in c:\users\aaron\appdata\roaming\python\python36\site-packages (from keras) (1.11.0)
Requirement already satisfied: keras-preprocessing>=1.0.5 in c:\users\aaron\anaconda3\envs\venv\lib\site-packages (from keras) (1.0.5)
Collecting scipy>=0.14 (from keras)
  Downloading https://files.pythonhosted.org/packages/c4/0f/2bdeab43db2b4a75863863bf7eddda8920b031b0a70494fd2665c73c9aec/scipy-1.2.0-cp36-cp36m-win_amd64.whl (31.9MB)
    100% |████████████████████████████████| 31.9MB 369kB/s
Installing collected packages: pyyaml, scipy, keras
Successfully installed keras-2.2.4 pyyaml-3.13 scipy-1.2.0

I then closed the Anaconda Prompt window and relaunched it, and didn't have any problems:

(base) C:\Users\Aaron>

So, to recap, DO NOT USE CONDA, USE PIP to install TensorFlow and Keras!

  1. Windows users should use Revo Uninstaller to delete and remove Anaconda and registry remnants with advanced scan settings.
  2. Download and install the latest Anaconda version with Python 3.7 or choose 3.6.
  3. If you download 3.7, Open Anaconda Prompt and create a Python 3.6 virtual environment.
  4. While in the virtual environment, do a pip install of the specific version of tensorflow that is supported for your OS and Python version, see the list above.
  5. While in virtual environment, do a pip install of keras.
  6. Make sure you remember to activate the virutal environment whenever you wanna use TensorFlow.
  7. Reinstall any pip python libraries you had.

I hope this helps anyone who had this problem too.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source