Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keras breaks Anaconda Prompt

I am switching from tensorflow to keras on my Anaconda distribution and am having some problems with the latter. I install it through Anaconda prompt with the command

conda install keras

and I do not think the installation is properly finished since it runs the command

python -c "import keras"  1>nul 2>&1

and closes the prompt. Afterwards, if I am to open the command line it automatically runs the command above and closes it, so I am unable to use the prompt. This has happened for both Anaconda 5.3.1 (Python 3.7) and Anaconda 5.2.0 (Python 3.6).

Thank you very much in advance. Any help will be much appreciated.

like image 558
Ahab Avatar asked Nov 26 '18 14:11

Ahab


2 Answers

I tried almost every solution to this problem (erasing "nul" from activate.d seemed to work at first, but then conda commands related to packages still crashed the prompt). So this is what I did. The problems seems to originate in the way that conda installs keras.

1) Uninstall keras using pip. Use the Scripts folder in the Anaconda installation folder.

2) Manually delete every remaining folder from Keras. Most of them are located in the Anaconda installation folder. Don't forget to delete the keras_activate.bat and keras_deactive.bat files in the activate.d and deactivate.d folders.

3) Install keras using pip.

4) That solves the activate.d problem. However, Anaconda Prompt still crashes because of the other file in the %UserProfile%Anaconda3/etc/conda folder, which is called vs2015_compiler_vars.bat. Delete that file and everything will work just fine (weird error messages that appeared while using Keras will also go away).

P.S. I went through one extra step to make Anaconda Prompt work perfectly, but I don't know if it is related to installing Keras (that's the reason why I am not including it in the answer). As conda commands were getting stuck in "Solving environment", I enabled strich channel priority with conda config --set channel_priority strict. Now Anaconda is totally functional!

like image 100
J.M. Molina Avatar answered Nov 20 '22 04:11

J.M. Molina


I figured out the answer after combining answers from GAURAV and GYAN ARORA. The solution is this:

1) Go to %UserProfile%Anaconda3/etc/conda/activate.dand right click on keras_activate.bat 2) Click on edit. This is what the .bat file looks like:

:: Figure out the default Keras backend by reading the config file.
python %CONDA_PREFIX%\etc\keras\load_config.py > temp.txt
set /p KERAS_BACKEND=<temp.txt
del temp.txt

:: Try to use the default Keras backend.
:: Fallback to Theano if it fails (Theano always works).
python -c "import keras" 1>nul 2>&1
if errorlevel 1 (
    ver > nul
    set "KERAS_BACKEND=theano"
    python -c "import keras" 1>nul 2>&1
)

Change both 1>nul to 1>. The final file should look like this:

:: Figure out the default Keras backend by reading the config file.
python %CONDA_PREFIX%\etc\keras\load_config.py > temp.txt
set /p KERAS_BACKEND=<temp.txt
del temp.txt

:: Try to use the default Keras backend.
:: Fallback to Theano if it fails (Theano always works).
python -c "import keras" 1> 2>&1
if errorlevel 1 (
    ver > nul
    set "KERAS_BACKEND=theano"
    python -c "import keras" 1> 2>&1
)

3) Save and close

like image 8
Vishesh Shrivastav Avatar answered Nov 20 '22 05:11

Vishesh Shrivastav