当前位置:   article > 正文

VS Code 远程SSH连接Mac OS失败解决方法_vscode远程连接显示bash: powershell: command not found

vscode远程连接显示bash: powershell: command not found

Mac OS 12.3 Remote-SSH vscode-server failed to start问题

适用情况:通过vscode的remote-ssh插件连接到mac os 12.3报错

升级到Mac OS 12.3后由于默认的python2被移除,Zsh shell(Bash同理)中输入python会显示Command not found。这会导致Remote-SSH连接时,vscode-server找不到python的命令,进而无法启动服务并使Remote-SSH插件连接失败。

关键错误提示:

  1. #正式版的插件错误日志可能略有不同,大差不差
  2. */bin/code-server-insiders: line 10: python: command not found
  3. usage: dirname string [...]
  4. usage: dirname string [...]
  5. */bin/code-server-insiders: line 13: /node: No such file or directory

无效的常见解决方法

  • 使用command + shift + P,运行Remote-SSH: Kill VS Code Server on Host
  • 在Mac上运行rm -rf ~/.vscode-server,删除整个.vscode-server重新安装服务端
  • 升级g++等编译环境

有效解决办法

  • 在mac上制作一个symbolic link,将python连接到现存的python3上。我没有尝试过这个方法。以下是github上issue中的原文

    Hey @jazaval , I'm having the exact same issue after a recent update.

    I tried to add an alias to python3 in ~/.zsrcr~/.bashrc and ~/.bash_profile or add /usr/local/opt/python/libexec/bin to the PATH, but none of those solutions worked (I'm connecting with the same user).
    Symlink worked. If you installed python3 with brew install python:ln -s /usr/local/Frameworks/Python.framework/Versions/Current/bin/python3 /usr/local/bin/python

  • 将brew安装的Python3路径导入到~/.zprofile里面,以及~/.zshenv里面,理论上说,anaconda或者miniforge的python也是可以的,只要有一个确定的PATH就行了。我使用此方法解决有效

    1. # Make sure you have python3 from brew
    2. brew install python
    3. # Add the unversioned symlinks to the PATH
    4. echo export PATH=\\"$(brew --prefix)/opt/python/libexec/bin:\\$PATH\\" >> ~/.zprofile
    5. # This worked for me too, but I needed to set it up in ~/.zshenv

附带问题:

 如果你是anaconda、miniforge或者是任意的python环境用户,你通过Remote-SSH连接到Mac时,在默认的base环境(或者你conda activate任意环境),执行which python会发现默认的python解释器不是conda路径下的,而是之前导入到.zprofile里面的路径,不管你如何切换环境都是如此。

解决方法:

1、conda deactivate一下,然后再conda activate <你的环境>。

2、如果是Zsh用户且第一步还没解决你的问题,可以执行source ~/.zshrc,前提是你的zshrc中放了conda的初始化语句,然后再执行第一步

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/在线问答5/article/detail/740068
推荐阅读
相关标签
  

闽ICP备14008679号