Error : Failed to create temp directory "C:\Users\user\AppData\Local\Temp\conda-<RANDOM>\"
Asked Answered
E

5

12

When I try to Activate "conda activate tensorflow_cpu"

conda activate tensorflow_cpu

Error : Failed to create temp directory "C:\Users\user\AppData\Local\Temp\conda-\"

Ethanol answered 21/3, 2020 at 15:48 Comment(1)
Please provide some information on your environment.Groce
J
20

It is due to a bug from conda developers. The bug is the temp path is having names with spaces, so to overcome please reassign the Env Variables TEMP, TMP. (for windows)

  1. go to environment variables
  2. In "User Variables for " section look for TEMP, TMP
  3. double click on TMP and in "variable value", type "C:\conda_tmp"
  4. similarly do it for TEMP
  5. close env variables section
  6. Restart the anaconda prompt, the error should vanish
Jab answered 9/5, 2020 at 6:37 Comment(0)
C
3

Making a little tempory workaround by editing "C:\ProgramData\Anaconda3\Scripts\activate.bat" to add the following just before the first "@if" :

@set TEMP=C:/temp
@set TMP=C:/temp

This is avoid modifying the whole thing by changing Env variable as mentioned by some of the users.

Thanks to Hepson for this suggestion

Cambridgeshire answered 10/10, 2020 at 15:2 Comment(0)
B
2

I came across this error as well. I was following the instructions to update Spyder. When I opened the Anaconda Prompt (Anaconda3) I got the following error:

Failed to create temp directory "C:\Users\username with spaces\AppData\Local\Temp\conda<RANDOM>\"

Which this led to the following error coming up when I tried 'conda update anaconda':

'conda' is not recognized as an internal or external command, operable program or batch file.

The above solution may work for Anaconda, but I was hesitant about it's effect on other applications that use the TEMP and TMP folders. So after further research I came across a series of issues on GitHub https://github.com/conda/conda/issues/9757 which points to the root cause being that it's unable to handle Windows user names with spaces in them, at least for me, not sure about the OP, my assumption is @Hassan masked his name?

My workaround was to open the Anaconda Powershell Prompt, it seems to be updating just fine within this prompt.

Brewing answered 8/6, 2020 at 16:52 Comment(2)
were you having the exact error? Or a similar one?Brewing
Yes, the same error. What worked for me was my answerCambridgeshire
W
0

looking @Kurian Benoy's answer seems to work best, but his file path was different than the one I needed.

Essentially look for the 'programdat' or 'programdata' in 'C' and look for 'condabin'

the file i found was '_conda_activate.bat'

and basically add the same lines above the first '@if'

@set TEMP=C:/temp
@set TMP=C:/temp

but also to check, open a anaconda prompt and activate your environment using

conda activate <environment name>
Whig answered 8/4, 2021 at 15:0 Comment(0)
B
0

The root cause is that your TEMP folder has not been cleaned up periodically.

Whenever conda activate runs, it would create a conda-<RANDOM> folder under TEMP. conda's <RANDOM> number have upper limit 32768 - so after almost every <RANDOM> number has been exhausted for path %TEMP%\conda-<RANDOM>, conda would fail. Therefore you'd need to clean up your %TEMP%\conda-* periodically. Even if you change your conda to use another path like others mentioned, you'd also need to clean up the new path.

For someone interested in conda's source code, it is using %RANDOM% command to get random number. If it tried 100 times and still cannot find a valid random number, it would fail:

@FOR /L %%I IN (1,1,100) DO @(
    SET UNIQUE_DIR=%TMP%\conda-!RANDOM!
    MKDIR !UNIQUE_DIR! > NUL 2>&1
    IF NOT ERRORLEVEL 1 (
        SET UNIQUE=!UNIQUE_DIR!\conda.tmp
        TYPE NUL 1> !UNIQUE!
        GOTO tmp_file_created
    )
)

According to https://ss64.com/nt/syntax-random.html: The Windows CMD shell contains a built-in variable called %RANDOM% that can be used to generate random numbers. %RANDOM% generates a random integer from 0 to 32,767 (inclusive)

Bascom answered 3/6 at 15:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.