VS Code 远程SSH连接Mac OS失败解决方法

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插件连接失败。

关键错误提示:

#正式版的插件错误日志可能略有不同,大差不差
*/bin/code-server-insiders: line 10: python: command not found
usage: dirname string [...]
usage: dirname string [...]
*/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就行了。我使用此方法解决有效

  • # Make sure you have python3 from brew
    brew install python
    
    # Add the unversioned symlinks to the PATH
    echo export PATH=\\"$(brew --prefix)/opt/python/libexec/bin:\\$PATH\\" >> ~/.zprofile
    # 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的初始化语句,然后再执行第一步

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值