Table of contents
foreword
Recently, because I need to execute some python scripts on MACOS, I installed a MACOS virtual machine. However, the default python version installed on MAC is 2.7.10, and the script is written based on python3. In order to execute the script smoothly, I started to upgrade the python version.
1. Download the installation package
Go to the python official website https://www.python.org/ , find the corresponding version package and download it.
2. python installation
2.1 Find the downloaded installation package, double-click to install:
2.2 Install step by step according to the guide:
During the period, there will be operations such as confirming the agreement, entering the password, etc., just follow the prompts.
2.3 Wait for the installation to complete
2.4 After the installation is complete:
3 Verify installation
python -V
Execute and respectively, python3 -V
you can see that there are currently 2 versions of python:
4 Modify the default Python version
Now the default python version is still 2.7.10, you need to modify the environment variable to change the default version to the newly installed version 3.11.2.
4.1 View the path of python3:
Execute which python3
the path to view python3:
4.2 Modify the .bash_profile file:
Open the terminal, execute vim ~/.bash_profile
, insert in the corpus alias python="/usr/local/bin/python3"
, and save:
4.3 Application environment variables:
Open the terminal and press source ~/.bash_profile
Enter to make the configuration just written take effect. At this point, the input python -V
will default to version 3.11:
5 install pip
In order to facilitate the management of python packages, install a pip here by the way
5.1 Get get-pip.py
Execute the command in the terminal curl 'https://bootstrap.pypa.io/get-pip.py' > get-pip.py
to get get-pip.py
5.2 Execute pip installation:
Execute the command to install pip in the terminal python get-pip.py
:
5.3 Check pip version:
Execute in the terminal pip -V
to check the version of pip:
5.4 Use pip to install the required packages:
Execute in the terminal pip install 包名
to install the required packages: