microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.65k stars 29.43k forks source link

Conda environment cannot initialized in VSCode at certain folder #204956

Open Zhangyanbo opened 9 months ago

Zhangyanbo commented 9 months ago

Does this issue occur when all extensions are disabled?: Yes/No

Steps to Reproduce:

  1. I cannot reproduce this since it happens without any clue
  2. Open one folder, then the terminal will show this:
# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<

    Traceback (most recent call last):
      File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/conda/exception_handler.py", line 17, in __call__
        return func(*args, **kwargs)
      File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/conda/cli/main.py", line 110, in main_sourced
        print(activator.execute(), end="")
      File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/conda/activate.py", line 203, in execute
        return getattr(self, self.command)()
      File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/conda/activate.py", line 168, in activate
        builder_result = self.build_activate(self.env_name_or_prefix)
      File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/conda/activate.py", line 347, in build_activate
        return self._build_activate_stack(env_name_or_prefix, False)
      File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/conda/activate.py", line 437, in _build_activate_stack
        deactivate_scripts = self._get_deactivate_scripts(old_conda_prefix)
      File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/conda/activate.py", line 769, in _get_deactivate_scripts
        for entry in os.scandir(join(prefix, "etc", "conda", "deactivate.d"))
      File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/posixpath.py", line 76, in join
        a = os.fspath(a)
    TypeError: expected str, bytes or os.PathLike object, not NoneType

`$ /opt/homebrew/Caskroom/miniforge/base/bin/conda shell.posix activate base`

  environment variables:
                 CIO_TEST=<not set>
                CONDA_EXE=/opt/homebrew/Caskroom/miniforge/base/bin/conda
           CONDA_PREFIX_2=/opt/homebrew/Caskroom/miniforge/base/envs/ML
           CONDA_PREFIX_3=/opt/homebrew/Caskroom/miniforge/base
         CONDA_PYTHON_EXE=/opt/homebrew/Caskroom/miniforge/base/bin/python
               CONDA_ROOT=/opt/homebrew/Caskroom/miniforge/base
              CONDA_SHLVL=4
           CURL_CA_BUNDLE=<not set>
                 INFOPATH=/opt/homebrew/share/info:
               LD_PRELOAD=<not set>
                  MANPATH=/opt/homebrew/share/man:/usr/share/man:/usr/local/share/man:/opt/X11/s
                          hare/man:/Library/TeX/Distributions/.DefaultTeX/Contents/Man:/opt/home
                          brew/share/man::
                     PATH=/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/
                          App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.
                          cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.secur
                          ity.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.securit
                          y.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/X11/bin:/
                          Library/Apple/usr/bin:/Library/TeX/texbin
       REQUESTS_CA_BUNDLE=<not set>
            SSL_CERT_FILE=<not set>

     active environment : None
            shell level : 4
       user config file : /Users/yanbozhang/.condarc
 populated config files : /opt/homebrew/Caskroom/miniforge/base/.condarc
          conda version : 23.11.0
    conda-build version : not installed
         python version : 3.9.18.final.0
                 solver : libmamba (default)
       virtual packages : __archspec=1=m1
                          __conda=23.11.0=0
                          __osx=14.2.1=0
                          __unix=0=0
       base environment : /opt/homebrew/Caskroom/miniforge/base  (writable)
      conda av data dir : /opt/homebrew/Caskroom/miniforge/base/etc/conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/osx-arm64
                          https://conda.anaconda.org/conda-forge/noarch
          package cache : /opt/homebrew/Caskroom/miniforge/base/pkgs
                          /Users/yanbozhang/.conda/pkgs
       envs directories : /opt/homebrew/Caskroom/miniforge/base/envs
                          /Users/yanbozhang/.conda/envs
               platform : osx-arm64
             user-agent : conda/23.11.0 requests/2.31.0 CPython/3.9.18 Darwin/23.2.0 OSX/14.2.1 solver/libmamba conda-libmamba-solver/23.12.0 libmambapy/1.5.6
                UID:GID : 501:20
             netrc file : /Users/yanbozhang/.netrc
           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>

^C
Timeout reached. No report sent.

Notes

chenyifanthu commented 8 months ago

Me too! Have u solved this problem?

Zhangyanbo commented 8 months ago

Me too! Have u solved this problem?

@chenyifanthu See this issue in conda repo: https://github.com/conda/conda/issues/13585#issuecomment-1987090935 Not an elegant solution, but it works.

lilian-83 commented 8 months ago

As I stated here conda/conda#13585 (comment), I think it's a VSCode problem after investigating the issue and trying some fixes.

@meganrogge I still didn't figure out the problem but it happens to me only under these conditions:

I think the issue happens somehow when the environment variables are set to activate the specific ML environment. When staying in the above "bug" conditions, comparing environments variables from the "buggy" terminal with another one where I selected another conda env (say test) as Python interpreter, I see some differences: CONDA_PREFIX variable is set for test, not for ML (only CONDA_PREFIX_2 and later are defined for ML), CONDA_DEFAULT_ENV is set for test but not for ML, /Users/lilianbonnet/miniconda3/envs/test/bin and other paths are added to PATH for test but not for ML), and other variables are different.