CondaValueError: Value error: prefix already exists:
Asked Answered
I

6

30

Reference:

https://uoa-eresearch.github.io/eresearch-cookbook/recipe/2014/11/20/conda/

I've run the following commands to install conda and create a virtual environment. Continue reading after code block for my question.

C:\Windows\System32>conda -V
conda 4.1.11

C:\Windows\System32>conda update conda
Fetching package metadata .........
Solving package specifications: ..........

Package plan for installation in environment C:\Program Files\Miniconda2:

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    conda-env-2.6.0            |                0          498 B
    enum34-1.1.6               |           py27_0          53 KB
    conda-4.2.9                |           py27_0         421 KB
    ------------------------------------------------------------
                                           Total:         475 KB

The following NEW packages will be INSTALLED:

    enum34:    1.1.6-py27_0

The following packages will be UPDATED:

    conda:     4.1.11-py27_0 --> 4.2.9-py27_0
    conda-env: 2.5.2-py27_0  --> 2.6.0-0

Proceed ([y]/n)? y

Fetching packages ...
conda-env-2.6. 100% |###############################| Time: 0:00:00  99.60 kB/s
enum34-1.1.6-p 100% |###############################| Time: 0:00:00 719.03 kB/s
conda-4.2.9-py 100% |###############################| Time: 0:00:00   1.33 MB/s
Extracting packages ...
[      COMPLETE      ]|##################################################| 100%
Unlinking packages ...
[      COMPLETE      ]|##################################################| 100%
Linking packages ...
[      COMPLETE      ]|##################################################| 100%

C:\Windows\System32>


C:\Windows\System32>Python -V
Python 2.7.12

C:\Windows\System32>conda create -n ENV1 python=2.7.12 anaconda

...

<-- chose 'n' for install

I chose 'n' here, because this is when I crashed my Linux server because I ran out of disk space when a billion programs (give or take) were asked to be installed. Instead, I chose 'n', and then wanted to log this to a file so I could see the entire list because I couldn't scroll up in the Windows command prompt, so I ran the code below instead. It sat for a while, and then I broke out using CTRL+C. Continue reading after code block for my question.

C:\Windows\System32>conda create -n ENV1 python=2.7.12 anaconda > C:\output.txt

y
Traceback (most recent call last):
  File "C:\Program Files\Miniconda2\Scripts\conda-script.py", line 5, in <module
>
    sys.exit(conda.cli.main())
  File "C:\Program Files\Miniconda2\lib\site-packages\conda\cli\main.py", line 1
50, in main
    return conda_exception_handler(_main)
  File "C:\Program Files\Miniconda2\lib\site-packages\conda\exceptions.py", line
 473, in conda_exception_handler
    return_value = func(*args, **kwargs)
  File "C:\Program Files\Miniconda2\lib\site-packages\conda\cli\main.py", line 1
44, in _main
    exit_code = args.func(args, p)
  File "C:\Program Files\Miniconda2\lib\site-packages\conda\cli\main_create.py",
 line 68, in execute
    install(args, parser, 'create')
  File "C:\Program Files\Miniconda2\lib\site-packages\conda\cli\install.py", lin
e 405, in install
    execute_actions(actions, index, verbose=not context.quiet)
  File "C:\Program Files\Miniconda2\lib\site-packages\conda\plan.py", line 643,
in execute_actions
    inst.execute_instructions(plan, index, verbose)
  File "C:\Program Files\Miniconda2\lib\site-packages\conda\instructions.py", li
ne 134, in execute_instructions
    cmd(state, arg)
  File "C:\Program Files\Miniconda2\lib\site-packages\conda\instructions.py", li
ne 47, in FETCH_CMD
    fetch_pkg(state['index'][arg + '.tar.bz2'])
  File "C:\Program Files\Miniconda2\lib\site-packages\conda\fetch.py", line 336,
 in fetch_pkg
    download(url, path, session=session, md5=info['md5'], urlstxt=True)
  File "C:\Program Files\Miniconda2\lib\site-packages\conda\fetch.py", line 419,
 in download
    for chunk in resp.iter_content(2**14):
  File "C:\Program Files\Miniconda2\lib\site-packages\requests\models.py", line
664, in generate
    for chunk in self.raw.stream(chunk_size, decode_content=True):
  File "C:\Program Files\Miniconda2\lib\site-packages\requests\packages\urllib3\
response.py", line 353, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "C:\Program Files\Miniconda2\lib\site-packages\requests\packages\urllib3\
response.py", line 310, in read
    data = self._fp.read(amt)
  File "C:\Program Files\Miniconda2\lib\httplib.py", line 612, in read
    s = self.fp.read(amt)
  File "C:\Program Files\Miniconda2\lib\socket.py", line 384, in read
    data = self._sock.recv(left)
  File "C:\Program Files\Miniconda2\lib\ssl.py", line 756, in recv
    return self.read(buflen)
  File "C:\Program Files\Miniconda2\lib\ssl.py", line 643, in read
    v = self._sslobj.read(len)
KeyboardInterrupt

C:\Windows\System32>conda create -n ENV1 python=2.7.12 anaconda > C:\output.txt

CondaValueError: Value error: prefix already exists: C:\Program Files\Miniconda2
\envs\ENV1

How can I remove the ENV1 prefix so I can try re-installing? And how can I log all of this output in Windows. The input is not visible if I move to C:\output.txt.

Infidelity answered 21/10, 2016 at 15:40 Comment(3)
conda env remove -n ENV1 should remove the environment. BTW, there seems to be a bug or something lately that the conda create or conda install or conda update scripts take a while to finish, once they appear to have finished (i.e., stop printing output). You might have to wait a few minutes to get a command prompt back. Also, it is not necessary to install all of anaconda unless you really want to. You can install individual packages and then you won't have a billion (give or take) installingGolding
How would I choose which packages to install?Infidelity
I dunno, basically, when you decide you need a package you install it. What are you trying to do?Golding
I
38

I simply deleted folder C:\Program Files\Miniconda2\envs\ENV1\.

Infidelity answered 5/11, 2016 at 6:48 Comment(3)
where is this folder for normal Conda? Can't find itEchidna
you can find it in here C:\ProgramData\Anaconda3\envsNeace
This feels like not the best way, surely removing the environment conda env remove or forcing the overwrite --force are preferable?Prolongation
B
36

You can overwrite the existing enviroment by adding the --force option.

So:

conda create -n ENV1 python=2.7.12 anaconda --force

Make sure that you have updated you anaconda because it is a recent function.

Edit: --force feature was added in conda 4.6, but apparently on latest versions 4.7, 4.8, it doesn't always work

Bystreet answered 17/12, 2019 at 14:59 Comment(1)
--force feature was added in conda 4.6, but apparently on latest versions 4.7, 4.8, it doesn't always work: github.com/conda/conda/issues/7819#issuecomment-611657889Tavares
S
6

You can just deactivate the existing one and remove it and then create the new one.

    conda deactivate
    conda env remove -n env_name
Silkstocking answered 28/6, 2022 at 11:49 Comment(0)
T
2

When the conda environment was previously removed, but the actual directory still exists (for some reason), then the "conda env remove -n ENV1" will do nothing:

$ conda-env list

  # conda environments:
  #
  base                  *  /home/nmanos/miniconda
  test-env                 /home/nmanos/miniconda/envs/test-env

$ conda-env remove -n ENV1
# Nothing was removed (exit code zero)   

$ ls /home/nmanos/miniconda/envs/ENV1  
  bin  conda-meta  etc  go
# Directory still exists

So you can remove the actual ENV1 directory, as follow:

$ ENV_BASE=$(conda-env list | awk '/base/ { print $NF }')
$ echo $ENV_BASE
  /home/nmanos/miniconda

$ rm -rf "$ENV_BASE/envs/ENV1"
Tavares answered 7/5, 2020 at 10:26 Comment(0)
M
2
  1. Open your environment.yml file
  2. Check the name and prefix of the environment, usually at the first line (name) and the last line (prefix) of the file.
  3. Rename both the name and prefix path to whatever name you are trying to create the new environment.
  4. Run the create env command again.
  5. conda env list should give your new environment now.

It is most likely that you are having the name (& prefix) of the other env which is already existing from where you got the environment.yml.

Mosesmosey answered 1/5, 2022 at 10:32 Comment(1)
This is the best answer in my opinion.Reclaim
T
-1

The next time you open the terminal and the prompt is (base) C:\Users\whatever> Just type: (base) C:\Users\whatever> conda activate ENV1

Your prompt should change to: (ENV1) C:\Users\whatever>

And once your work is done just say: (ENV1) C:\Users\whatever> conda deactivate

Because it's obviously inconvenient to keep deleting the folder over and over

Touristy answered 8/4, 2018 at 10:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.