Conda exception on start of vscode, exceptinon reported inside of vscode terminal

Not sure what to do. I have been using vscode for quite a while now with no issues.

exec summary
When I started vscode today, with base env activated I get an exception (see below) in the vscode terminal. It only happens if I start vscode in base env. If I start in another env I can get the exception by deactivating and falling into base env.

I have ripped out all my env, ripped out miniconda, ripped out vscode, put in updated versions of both, and get the same issue. So that is, I see the problem with a completely fresh install of both, that is with base env only and a new clean install of vscode without any extensions added.

Would be very interested how to fix this.

LONG STORY

Today when it starts I get the following conda exception in the terminal within vscode:


# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<

    Traceback (most recent call last):
      File "/opt/miniconda3/lib/python3.12/site-packages/conda/exception_handler.py", line 18, in __call__
        return func(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^
      File "/opt/miniconda3/lib/python3.12/site-packages/conda/cli/main.py", line 87, in main_sourced
        print(activator.execute(), end="")
              ^^^^^^^^^^^^^^^^^^^
      File "/opt/miniconda3/lib/python3.12/site-packages/conda/activate.py", line 238, in execute
        response = getattr(self, self.command)()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/miniconda3/lib/python3.12/site-packages/conda/activate.py", line 200, in activate
        builder_result = self.build_activate(self.env_name_or_prefix)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/miniconda3/lib/python3.12/site-packages/conda/activate.py", line 367, in build_activate
        return self._build_activate_stack(env_name_or_prefix, False)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/miniconda3/lib/python3.12/site-packages/conda/activate.py", line 391, in _build_activate_stack
        return self.build_reactivate()
               ^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/miniconda3/lib/python3.12/site-packages/conda/activate.py", line 578, in build_reactivate
        self._replace_prefix_in_path(conda_prefix, conda_prefix)
      File "/opt/miniconda3/lib/python3.12/site-packages/conda/activate.py", line 724, in _replace_prefix_in_path
        if path_list[last_idx + 1] == library_bin_dir:
           ~~~~~~~~~^^^^^^^^^^^^^^
    IndexError: list index out of range

`$ /opt/miniconda3/bin/conda shell.posix activate base`

 environment variables:
        AMENT_PREFIX_PATH=/opt/ros/iron
                 CIO_TEST=<not set>
        CONDA_DEFAULT_ENV=base
                CONDA_EXE=/opt/miniconda3/bin/conda
             CONDA_PREFIX=/opt/miniconda3
    CONDA_PROMPT_MODIFIER=(base)
         CONDA_PYTHON_EXE=/opt/miniconda3/bin/python
               CONDA_ROOT=/opt/miniconda3
              CONDA_SHLVL=1
           CURL_CA_BUNDLE=<not set>
          LD_LIBRARY_PATH=/opt/ros/iron/opt/rviz_ogre_vendor/lib:/opt/ros/iron/lib/x86_64-linux-
                          gnu:/opt/ros/iron/lib
               LD_PRELOAD=<not set>
                     PATH=/opt/ros/iron/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/s
                          bin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/opt/minicond
                          a3/condabin:/opt/miniconda3/bin
               PYTHONPATH=/opt/ros/iron/lib/python3.10/site-packages
       REQUESTS_CA_BUNDLE=<not set>
            SSL_CERT_FILE=<not set>
               WINDOWPATH=2

     active environment : base
    active env location : /opt/miniconda3
            shell level : 1
       user config file : /home/asterion/.condarc
 populated config files : /opt/miniconda3/.condarc
                          /home/asterion/.condarc
          conda version : 24.11.1
    conda-build version : not installed
         python version : 3.12.8.final.0
                 solver : libmamba (default)
       virtual packages : __archspec=1=zen3
                          __conda=24.11.1=0
                          __cuda=12.7=0
                          __glibc=2.35=0
                          __linux=6.8.0=0
                          __unix=0=0
       base environment : /opt/miniconda3  (writable)
      conda av data dir : /opt/miniconda3/etc/conda
  conda av metadata url : None
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /opt/miniconda3/pkgs
                          /home/asterion/.conda/pkgs
       envs directories : /opt/miniconda3/envs
                          /home/asterion/.conda/envs
               platform : linux-64
             user-agent : conda/24.11.1 requests/2.32.3 CPython/3.12.8 Linux/6.8.0-51-generic ubuntu/22.04.5 glibc/2.35 solver/libmamba conda-libmamba-solver/24.9.0 libmambapy/1.5.11
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False


An unexpected error has occurred. Conda has prepared the above report.
If you suspect this error is being caused by a malfunctioning plugin,
consider using the --no-plugins option to turn off plugins.

Example: conda --no-plugins install <package>

Alternatively, you can set the CONDA_NO_PLUGINS environment variable on
the command line to run the command without plugins enabled.

Example: CONDA_NO_PLUGINS=true conda install <package>


Timeout reached. No report sent.

The problem was weird because it only seemed to be a problem for the “base”. If I started code in another env other than base, I didn’t get the exception. Then eventually I seemed to be able to start two windows in code with one call to code?!?! Both would have a different env set in the vscode terminal (not necessarily the one code was started in). If code was started in something other that base, I could cause the exception by deactivating the env in the vscode terminal to return to base env.

Can you run conda init --reverse and then conda init?

Yep. If I close vscode and do it in the bash shell (closing and opening shells for changes to take effect), then open vscode again, I get 2 vscode windows open, both with the exception in the vscode terminal.

@jaimergp so I created base2 with:

conda create -n base2
conda activate base2

If I start vscode in base2, vscode starts with no exception in its terminal but it’s terminal is reporting (base).

In the vscode terminal I use conda deactivate, conda changes to (base2).

If I use conda deactivate again inside vscode terminal, it drops out of conda envs, with no exception.

If I close vscode, use conda deactivate to drop from (base2) to (base) and start vscode, the exception is back.

This is so strange because you are on a Linux machine (judging by the paths) and is somehow trying to get rid of a Windows-only PATH entry. If I were you, I’d go to the section of the code mentioned in the traceback (“/opt/miniconda3/lib/python3.12/site-packages/conda/activate.py”, line 724) and comment it out so it looks like this:

                # if path_list[last_idx + 1] == library_bin_dir:
                #     last_idx += 1

@jaimergp Weird?! I’ll say weird.

Hmmm.

I can’t even put my finger on when it started happening. As mentioned, I had a number of env that I was using and wasn’t ever really dropping into (base) when using vscode.

I’ll try your suggestion report once I poke around a little with that, thanks.