35

MacOS 12.3 无法正常使用code命令的解决方法

 2 years ago
source link: https://www.wyr.me/post/692
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
MacOS 12.3 无法正常使用code命令的解决方法
MacOS 12.3 无法正常使用code命令的解决方法

从MacOS 12.3 Beta版本开始,系统将不再内置python2且将无法正常安装python2,无论是intel芯片还是Apple芯片的设备都无法安装。原因是/usr/bin/python的软链接无法正常被删除或覆盖。并且默认不开启python3命令。

因此可能会导致一系列依赖python命令的应用程序无法运行。

例如将会遇到VS(Visual Studio Code)无法使用code命令。

➜  saas-web git:(892f9ef) ✗ code .
/usr/local/bin/code: line 6: python: command not found
/usr/local/bin/code: line 10: ./MacOS/Electron: No such file or directory

由此也可能导致"Visual Studio Code - Insiders" needs to be updated on macOS Monterey弹窗的问题。

相关问题及VS Code最终Merge的方案见链接:https://github.com/microsoft/vscode/pull/138582

即使用纯Shell方式代替python命令作为优选的方案。

在VS Code正式更新此代码之前可以通过修改/usr/local/bin/code文件解决:

#!/usr/bin/env bash
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.

function app_realpath() {
    SOURCE=$1
    while [ -h "$SOURCE" ]; do
        DIR=$(dirname "$SOURCE")
        SOURCE=$(readlink "$SOURCE")
        [[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE
    done
    SOURCE_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
    echo "${SOURCE_DIR%%${SOURCE_DIR#*.app}}"
}

APP_PATH="$(app_realpath "${BASH_SOURCE[0]}")"
if [ -z "$APP_PATH" ]; then
    echo "Unable to determine app path from symlink : ${BASH_SOURCE[0]}"
    exit 1
fi
CONTENTS="$APP_PATH/Contents"
ELECTRON="$CONTENTS/MacOS/Electron"
CLI="$CONTENTS/Resources/app/out/cli.js"
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" --ms-enable-electron-run-as-node "$@"
exit $?

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK