Skip to content

New feature of Python extension will change my conda environment settings. #22752

Closed as not planned

Description

Discussed in #22742

Originally posted by Roderick-Stinson January 11, 2024
Because of the feature of python extension, which is Activate Environments in Terminal Using Environment Variables, python extension will delete an environment variable $CONDA_PREFIX,
the show environment contributions file looks like this:
image
you can see there isn't a variable named CONDA_PREFIX, instead there are CONDA_PREFIX_2andCONDA_PREFIX_3.
this leads to crash of conda
image
So could you please help solve this question? It's really annoying. My current solution is add export CONDA_PREFIX=/home/wangzihan/miniconda3 in .bashrc

Activity

  1. lethefrost commented on Jan 17, 2024

    @lethefrost

    Same. I'm using macOS, zsh, and miniforge installed by homebrew. Even when I turned off the option terminal.integrated.shellIntegration.enabled I can no longer access my python environment installed by conda in the usual way. Seems like it breaks conda's initialization or path configs in .zshrc? Haven't quite got time digging into it yet, but here's my error reports/outputs for your information.

    [WARNING]: Console output during zsh initialization detected.
    
    some Powerlevel10k outputs...
    
    -- console output produced during zsh initialization follows --
    
    
    # >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<
    
        Traceback (most recent call last):
          File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.11/site-packages/conda/exception_handler.py", line 17, in __call__
            return func(*args, **kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^
          File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.11/site-packages/conda/cli/main.py", line 105, in main_sourced
            print(activator.execute(), end="")
                  ^^^^^^^^^^^^^^^^^^^
          File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.11/site-packages/conda/activate.py", line 199, in execute
            return getattr(self, self.command)()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.11/site-packages/conda/activate.py", line 165, in activate
            builder_result = self.build_activate(self.env_name_or_prefix)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.11/site-packages/conda/activate.py", line 343, in build_activate
            return self._build_activate_stack(env_name_or_prefix, False)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.11/site-packages/conda/activate.py", line 433, in _build_activate_stack
            deactivate_scripts = self._get_deactivate_scripts(old_conda_prefix)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.11/site-packages/conda/activate.py", line 765, in _get_deactivate_scripts
            for entry in os.scandir(join(prefix, "etc", "conda", "deactivate.d"))
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          File "<frozen posixpath>", line 76, in join
        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/envname
               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:/Library/T
                              eX/Distributions/.DefaultTeX/Contents/Man:/opt/homebrew/share/man::
                         PATH=/opt/homebrew/opt/python@3.11/libexec/bin:/Users/username/Library/Android
                              /sdk/tools:/Users/username/Library/Android/sdk/tools/bin:/Users/username/Lib
                              rary/Android/sdk/platform-tools:/opt/homebrew/bin:/opt/homebrew/sbin:/
                              usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/s
                              bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/lo
                              cal/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/us
                              r/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/
                              appleinternal/bin:/Library/Apple/usr/bin:/Library/TeX/texbin:/usr/loca
                              l/share/dotnet:~/.dotnet/tools
           REQUESTS_CA_BUNDLE=<not set>
                SSL_CERT_FILE=<not set>
    
         active environment : None
                shell level : 4
           user config file : /Users/username/.condarc
     populated config files : /opt/homebrew/Caskroom/miniforge/base/.condarc
              conda version : 23.9.0
        conda-build version : not installed
             python version : 3.11.0.final.0
           virtual packages : __archspec=1=m2
                              __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/username/.conda/pkgs
           envs directories : /opt/homebrew/Caskroom/miniforge/base/envs
                              /Users/username/.conda/envs
                   platform : osx-arm64
                 user-agent : conda/23.9.0 requests/2.31.0 CPython/3.11.0 Darwin/23.2.0 OSX/14.2.1
                    UID:GID : 501:20
                 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>
    
    
    # >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<
    
        Traceback (most recent call last):
          File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.11/site-packages/conda/exception_handler.py", line 17, in __call__
            return func(*args, **kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^
          File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.11/site-packages/conda/cli/main.py", line 105, in main_sourced
            print(activator.execute(), end="")
                  ^^^^^^^^^^^^^^^^^^^
          File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.11/site-packages/conda/activate.py", line 199, in execute
            return getattr(self, self.command)()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.11/site-packages/conda/activate.py", line 165, in activate
            builder_result = self.build_activate(self.env_name_or_prefix)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.11/site-packages/conda/activate.py", line 343, in build_activate
            return self._build_activate_stack(env_name_or_prefix, False)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.11/site-packages/conda/activate.py", line 433, in _build_activate_stack
            deactivate_scripts = self._get_deactivate_scripts(old_conda_prefix)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.11/site-packages/conda/activate.py", line 765, in _get_deactivate_scripts
            for entry in os.scandir(join(prefix, "etc", "conda", "deactivate.d"))
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          File "<frozen posixpath>", line 76, in join
        TypeError: expected str, bytes or os.PathLike object, not NoneType
    
    `$ /opt/homebrew/Caskroom/miniforge/base/bin/conda shell.posix activate envname`
    
      environment variables:
                     CIO_TEST=<not set>
                    CONDA_EXE=/opt/homebrew/Caskroom/miniforge/base/bin/conda
               CONDA_PREFIX_2=/opt/homebrew/Caskroom/miniforge/base/envs/envname
               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:/Library/T
                              eX/Distributions/.DefaultTeX/Contents/Man:/opt/homebrew/share/man::
                         PATH=/opt/homebrew/opt/python@3.11/libexec/bin:/Users/username/Library/Android
                              /sdk/tools:/Users/username/Library/Android/sdk/tools/bin:/Users/username/Lib
                              rary/Android/sdk/platform-tools:/opt/homebrew/bin:/opt/homebrew/sbin:/
                              usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/s
                              bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/lo
                              cal/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/us
                              r/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/
                              appleinternal/bin:/Library/Apple/usr/bin:/Library/TeX/texbin:/usr/loca
                              l/share/dotnet:~/.dotnet/tools
           REQUESTS_CA_BUNDLE=<not set>
                SSL_CERT_FILE=<not set>
    
         active environment : None
                shell level : 4
           user config file : /Users/username/.condarc
     populated config files : /opt/homebrew/Caskroom/miniforge/base/.condarc
              conda version : 23.9.0
        conda-build version : not installed
             python version : 3.11.0.final.0
           virtual packages : __archspec=1=m2
                              __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/username/.conda/pkgs
           envs directories : /opt/homebrew/Caskroom/miniforge/base/envs
                              /Users/username/.conda/envs
                   platform : osx-arm64
                 user-agent : conda/23.9.0 requests/2.31.0 CPython/3.11.0 Darwin/23.2.0 OSX/14.2.1
                    UID:GID : 501:20
                 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>
    

    and my ms-python.python extension in Environment changes file writes:

    - `MANPATH=/opt/homebrew/share/man::`
    - `CONDA_SHLVL=4`
    - `_CE_CONDA=`
    - `CONDA_ROOT=/opt/homebrew/Caskroom/miniforge/base`
    - `CONDA_PREFIX_3=/opt/homebrew/Caskroom/miniforge/base`
    - `CONDA_PREFIX_2=/opt/homebrew/Caskroom/miniforge/base/envs/envname`
    - `_CE_M=`
    - `XPC_SERVICE_NAME=0`
    - `PS1=(envname) ${env:PS1}`
    

    and in .zshrc I have the conda default initialization as

    # >>> conda initialize >>>
    # !! Contents within this block are managed by 'conda init' !!
    __conda_setup="$('/opt/homebrew/Caskroom/miniforge/base/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
    if [ $? -eq 0 ]; then
        eval "$__conda_setup"
    else
        if [ -f "/opt/homebrew/Caskroom/miniforge/base/etc/profile.d/conda.sh" ]; then
            . "/opt/homebrew/Caskroom/miniforge/base/etc/profile.d/conda.sh"
        else
            export PATH="/opt/homebrew/Caskroom/miniforge/base/bin:$PATH"
        fi
    fi
    unset __conda_setup
    # <<< conda initialize <<<

    and which conda outputs the following function:

    conda () {
    	\local cmd="${1-__missing__}"
    	case "$cmd" in
    		(activate | deactivate) __conda_activate "$@" ;;
    		(install | update | upgrade | remove | uninstall) __conda_exe "$@" || \return
    			__conda_reactivate ;;
    		(*) __conda_exe "$@" ;;
    	esac
    }

    Does anyone know what path I should assign to CONDA_PREFIX if I'm to try the workaround mentioned by several users? Thank you!

  2. okkymabruri commented on Jan 17, 2024

    @okkymabruri

    Hi Brett Cannon (@brettcannon) lethefrost
    I resolved that issue by enabling terminal.integrated.inheritEnv setting.

    "terminal.integrated.inheritEnv": true

  3. lethefrost commented on Jan 18, 2024

    @lethefrost

    Hi Brett Cannon (@brettcannon) lethefrost I resolved that issue by enabling terminal.integrated.inheritEnv setting.

    "terminal.integrated.inheritEnv": true

    Hi there Okky Mabruri (@okkymabruri) Thank you! It helps a lot! Seems like the new python extension automatically turned it false?

    Just for anyone also encountering the same issue: After reactivating this option, the python command still doesn't look for conda's python binaries by default (as possibly configured in shell's rc file). However, after running conda activate envName in the integrated shell, it can eventually find conda's pythons.

  4. karrtikr commented on Jan 23, 2024

    @karrtikr

    Hi all, apologies for the issue. Could anyone send us the debug logs which can help diagnose it:

    • Run Developer: Set log level command
    • Select Trace
    • Run Developer: Reload Window command
    • Provide the output:
    Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)

    XXX
    

  5. lethefrost commented on Jan 25, 2024

    @lethefrost

    Hi all, apologies for the issue. Could anyone send us the debug logs which can help diagnose it:

    • Run Developer: Set log level command
    • Select Trace
    • Run Developer: Reload Window command
    • Provide the output:

    Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)

    Hi there, what settings should these logs be running under, and is there any specific action we should do to ensure wanted information is logged?

  6. karrtikr commented on Jan 25, 2024

    @karrtikr

    No special settings needed other than the ones specified. Just open a Python file to activate the extension and make sure to perform the steps to reproduce the issue.

  7. brettcannon commented on Mar 13, 2024

    @brettcannon
    MemberAuthor

    Because we have not heard back with the information we requested, we are closing this issue for now. If you are able to provide the info later on, then we will be happy to re-open this issue to pick up where we left off.

  8. locked as resolved and limited conversation to collaborators on Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-environmentsFeatures relating to handling interpreter environmentstriage-neededNeeds assignment to the proper sub-team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions