Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
brettcannon opened this issue Jan 15, 2024 Discussed in #22742 · 7 comments
Closed

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

brettcannon opened this issue Jan 15, 2024 Discussed in #22742 · 7 comments
Assignees
Labels
area-environments Features relating to handling interpreter environments triage-needed Needs assignment to the proper sub-team

Comments

@brettcannon
Copy link
Member

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

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Jan 15, 2024
@anthonykim1 anthonykim1 added the area-environments Features relating to handling interpreter environments label Jan 16, 2024
@lethefrost
Copy link

lethefrost commented Jan 17, 2024

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/[email protected]/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/[email protected]/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!

@okkymabruri
Copy link

Hi @brettcannon @lethefrost
I resolved that issue by enabling terminal.integrated.inheritEnv setting.

"terminal.integrated.inheritEnv": true

@lethefrost
Copy link

Hi @brettcannon @lethefrost I resolved that issue by enabling terminal.integrated.inheritEnv setting.

"terminal.integrated.inheritEnv": true

Hi there @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.

@karrtikr
Copy link

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 (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

XXX

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Jan 23, 2024
@lethefrost
Copy link

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 (ViewOutput, 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?

@karrtikr
Copy link

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.

@brettcannon
Copy link
Member Author

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.

@brettcannon brettcannon closed this as not planned Won't fix, can't repro, duplicate, stale Mar 13, 2024
@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Mar 13, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-environments Features relating to handling interpreter environments triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

5 participants