After the Day 261/300 Mac update, Python cannot use command not found: python

Mac system version: 12.6

(1) Demand

Mac uses python normally, for example, python --versionthe version of python can be printed out in the terminal output.

(2) Status

input python --version, terminal displaycommand not found: python

Typing python3 --versiondoesn't work either.

(3) Analysis

After checking the information, it was found that after updating the system version, after Python, the previously built-in Python library has changed.

(4) Solve

1. Reinstall xcode

In the Mac ecosystem, Git was used before, and now Python has been added, and Xcode needs to be installed to make it more convenient to use.

I feel that Apple is also working hard to push tools.

2. Install xcode-select

The usefulness is that after finding no command, xcode-select will prompt to install a new command installation package.
The installation command is xcode-select --install;

3. Execute the python command line

Enter python --version, prompt, let install python, click OK, after installation, until the installation is complete.

Enter python --version, or not. But typing python3 --version, shows Python 3.9.6the instructions, python3 is already installed. According to Apple's official website, it is said that the built-in python has been upgraded to python3, and python2 is no longer built-in.

4. Add soft chain

sudo ln -s /Library/Developer/CommandLineTools/usr/bin/python3 /Library/Developer/CommandLineTools/usr/bin/python

Enter it again python --version, and the output isPython 3.9.6

Related commands

// 查看Python的安装目录
which python 

reference link

https://developer.apple.com/forums/thread/704099

Guess you like

Origin blog.csdn.net/xinghuowuzhao/article/details/127055058