Skip to content

$HOST environment variable is wrongly changed & missing context on .zshenv, .zshrc #23350

@tplobo

Description

@tplobo

Type: Bug

Behaviour & Steps to reproduce

I'm using mambaforge as an environment manager and run shells with zsh.

In my understanding one of the last updates made the "Python Interpreter" setting to be remembered and automatically retrieved when a project is opened. Which means the contents

# >>> conda initialize >>>
...
# <<< conda initialize <<<

are not needed in .zshrc anymore. This is nice, but it has created a few associated problems.

The first problem: this has modified some environment variables in terminals running an environment, for example:

(myenv) user@x86_64-apple-darwin13 > echo $HOST
x86_64-apple-darwin13...

instead of being equal to the output of hostname (opening vscode instance outside project folder):

user@computer > echo $HOST
computer

This is apparently a known issue with conda.

As a potential fix, I have tried to set a .vscode/.zshenv to enforce the proper value for HOST. But this is overwritten by the activation of the mamba environment, which happens after sourcing .zshenv. Here's the code:

# Fix `hostname` for conda environments
# See: https://github.com/conda/conda/issues/7031
echo "HOST=$HOST, hostname=$(hostname)"
if [[ "$HOST" == *"darwin"* ]]; then
    export HOST=$(scutil --get HostName)
    echo "(VSCode environment) Setting HOST to HostName: $HOST" 
fi

The second problem: to remedy that situation, I have migrated the lines in .zshenv to a .../activate.d/fix_host.sh file as a mamba post-activation script. However, due to VSCode automatically loading the Python Interpreter, the mamba environment is apparently never properly activated, so the post-activation scripts are never run. In fact, after opening VSCode in the project folder:

(myenv) user@x86_64-apple-darwin13 > mamba deactivate
Run 'mamba init' to be able to run mamba activate/deactivate
and start a new shell session. Or use conda to activate/deactivate.

and

(myenv) user@x86_64-apple-darwin13 > conda deactivate
CondaError: Run 'conda init' before 'conda deactivate'

so it looks like conda/mamba init are skipped.

Extension version: 2024.7.11241010
VS Code version: Code 1.89.0 (b58957e67ee1e712cebf466b995adf4c5307b2bd, 2024-05-01T02:10:10.196Z)
OS version: Darwin x64 23.4.0
Modes:

  • Python version (& distribution if applicable, e.g. Anaconda): 3.11.8
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Conda
  • Value of the python.languageServer setting: Default
User Settings


condaPath: "<placeholder>"

languageServer: "Jedi"

testing
• pytestArgs: "<placeholder>"
• pytestEnabled: true

Installed Extensions
Extension Name Extension Id Version
Active4D Theme gerane.Theme-Active4D 0.0.5
Amazon Q amazonwebservices.amazon-q-vscode 1.1.0
AWS Toolkit amazonwebservices.aws-toolkit-vscode 3.1.0
Eva Theme fisheva.eva-theme 2.6.1
GitHub Copilot GitHub.copilot 1.186.0
GitHub Copilot Chat GitHub.copilot-chat 0.15.0
GitHub Pull Requests GitHub.vscode-pull-request-github 0.88.0
GitLens — Git supercharged eamodio.gitlens 14.9.1
JavaScript Debugger ms-vscode.js-debug 1.89.0
JavaScript Debugger Companion Extension ms-vscode.js-debug-companion 1.1.2
JSON Tree View ChaunceyKiwi.json-tree-view 2.6.0
Jupyter ms-toolsai.jupyter 2024.4.0
Jupyter Cell Tags ms-toolsai.vscode-jupyter-cell-tags 0.1.9
Jupyter Keymap ms-toolsai.jupyter-keymap 1.1.2
Jupyter Notebook Renderers ms-toolsai.jupyter-renderers 1.0.17
Jupyter Slide Show ms-toolsai.vscode-jupyter-slideshow 0.1.6
Lua sumneko.lua 3.8.3
macOS Native Copy/Paste qt-kaneko.macos-native-copy-paste 1.2.2
Material Theme Icons equinusocio.vsc-material-theme-icons 1.2.2
PDF Preview analytic-signal.preview-pdf 1.0.0
Prettier - Code formatter esbenp.prettier-vscode 10.4.0
Property List Editor ivhernandez.vscode-plist 0.1.3
Python ms-python.python 2024.7.11241010
Python Debugger ms-python.debugpy 2024.6.0
python snippets frhtylcn.pythonsnippets 1.0.2
Restore Git Branch Tabs gkotas.restore-git-branch-tabs 0.4.1
Ruby LSP Shopify.ruby-lsp 0.5.21
Ruby Solargraph castwide.solargraph 0.24.1
Ruff charliermarsh.ruff 2024.20.0
Table Visualizer for JavaScript Profiles ms-vscode.vscode-js-profile-table 1.0.9
TIFF Preview analytic-signal.preview-tiff 1.0.1
TODO Highlight wayou.vscode-todo-highlight 1.0.5
VS Code Counter uctakeoff.vscode-counter 3.4.0
VSCode Great Icons emmanuelbeziat.vscode-great-icons 2.1.104
System Info
Item Value
CPUs Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz (12 x 3200)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) 2, 2, 3
Memory (System) 64.00GB (4.39GB free)
Process Argv --crash-reporter-id f2c256c7-7349-4739-8da9-43c6de0bfa57
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
vscod805:30301674
binariesv615:30325510
vsaa593cf:30376535
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
pythongtdpath:30769146
welcomedialogc:30910334
pythonidxpt:30866567
pythonnoceb:30805159
asynctok:30898717
pythontestfixt:30902429
pythonregdiag2:30936856
pyreplss1:30897532
pythonmypyd1:30879173
pythoncet0:30885854
2e7ec940:31000449
pythontbext0:30879054
accentitlementsc:30995553
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
cppperfnew:31000557
ccp2r3:30993541
dsvsc020:30976470
pythonait:31006305
dsvsc021:30996838
0ee40948:31013168
pythoncenvpt:31022790
dwnewjupytercf:31035177

Metadata

Metadata

Assignees

Labels

bugIssue identified by VS Code Team member as probable bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions