简体   繁体   中英

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.

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.d and 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

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).

PS 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!

I had the same problem, took me 2 days to finally get things working and many re-installs. This message comes from the following file. %UserProfile%Anaconda3/etc/conda/activate.d/keras_activate.bat. There is some issue in the code written in this file which closes the Anaconda prompt every time. I dont know how to solve it, perhaps someone else can suggest something, but one way to still do some essential tasks on your prompt window is -> RIGHT CLICK ON THE ABOVE MENTIONED FILE AND SELECT EDIT -> WRITE YOUR ANACONDA PROMPT COMMAND AT THE TOP OF THE FILE. (It will execute and then close.)

IN below line in .bat file nul is creating the problem and it is closing the terminal please remove nul and this will be solved. So change this

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

to this

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

I have the same problem. I didn't find a permanent fix, but before the script finishes running, you can escape it using ctrl+d , and you should be able to do whatever you want after that.

The best solution I found was ,

1.Uninstall Keras first

2.goto the location C:\\Users\\username\\AppData\\Local\\Continuum\\anaconda3\\etc\\conda\\activate.d

You can see the keras batch files inside in both activate.d and deactivate.d , which runs every time the anaconda prompt is opened.DELETE them.

3.Reinstall Keras.

This worked well for me.

Simply execute command: pip unistall keras

And delete activate.d and deactivate.d from C:\\ProgramData\\Anaconda3\\etc\\conda\\

And reopen Anaconda prompt

"> Change both 1>nul to 1>" - Did not worked for me...

But this fixed the issue:

  1. uninstall Keras pip uninstall keras
  2. go to C:\\Users\\<username>\\anaconda3\\etc\\conda and DELETE all files in these folders
  3. install Keras pip install keras

I execute the anaconda prompt under administrator right and remove/reinstall Keras. The problem is then solved.

However it still gives me Theano backend that I need to manually changed it.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM