Configure Proxy#
Before installing Python, be sure to configure the proxy environment to avoid installation failures due to issues like GitHub being inaccessible. It is recommended to use the Hiddify software system proxy mode. Enter the following command in the terminal to enable the terminal proxy.
export https_proxy="proxyaddress:port"
Install Homebrew and Xcode Command Line Tools#
Get the installation command for Homebrew from the Homebrew homepage as follows:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
The installation is divided into two steps. First, the script will install the Xcode command line tools, and after entering the password again, it will install Homebrew. After completing Homebrew, follow the command line prompts to add Homebrew to the PATH environment variable. At this point, entering python3 --version
in the terminal window will show that the Xcode command line tools come with a Python 3.9 environment.
Install Python 3#
Install Using Homebrew (Optional)#
To run a higher version or a specific version of Python 3, use Homebrew to install Python 3.12 and CMake.
brew install python
brew install cmake
It can be seen that Homebrew installs Python very simply and conveniently, defaulting to the latest version of Python and configuring the environment variables. Subsequently, you can continue to use pyenv, venv, and pip for package management and environment management. This is more suitable for lightweight needs on Mac (after all, it's a hard drive made of gold).
Install Using Anaconda (Recommended)#
The author works in deep learning, and using Anaconda for Python version and environment management is very convenient. However, Anaconda takes up a lot of system space (about 4GB), so it can also be installed on an external hard drive for easier migration of the running environment between multiple devices. Download the Anaconda installation package directly from the Anaconda official website or the Tsinghua mirror for installation.
Typically, runtime environments like JRE and Python are installed in macOS in the form of file directories and configured through a configuration file similar to bashrc in Linux to set environment variables. Installation tools usually automatically configure the environment variables. Unlike installing applications with dmg files, if you want to reinstall these contents, you need to delete the corresponding files in the directory. It is recommended to consult ChatGPT for specific methods.