[Environment configuration] Use Homebrew to install the specified python version in the Mac environment

Basic environment introduction

Mac version: macOS Monterey 12.6
Terminal environment: zsh
Installation tool: homebrew

Install python3.9

Use home brew to install the specified version of python

brew install [email protected]

After installation, use the command line to check whether the installation is successful. The figure below indicates that the installation is successful

python3.9

insert image description here

Configure Quick Start

How to reach the input pythonto start the specified version of python?
Answer: Configure the environment variable to make the startup.

If you do not need to start in this way, you can directly use the specified version in the pythonx.x way.

Check the environment variable file of this machine, here you can directly see the prompt of your command line terminal, here I use zsh to configure the environment variable, other environments are similar.
insert image description here

Check the installation of python according to the operation prompt in the figure below
insert image description here

Open and edit the zsh variable file

open -e ~/.zshrc 

Write the configuration path, ⚠️ Please make changes according to your actual environment

export PATH=$PATH:/usr/local/Cellar/[email protected]/3.9.16/bin
alias python="/usr/local/Cellar/[email protected]/3.9.16/bin/python3.9"

Configuration diagram display
insert image description here

After the configuration is complete, enter the command to load the variable file to make it take effect

 source ~/.zshrc

Finally, enter pythonthe version specified by the configuration to start
insert image description here

Guess you like

Origin blog.csdn.net/weixin_54430466/article/details/128888926