Python version management tool under macOS

野狼
·
·
IPFS
·

foreword

In the development of Python projects or on macOS, there are often problems with the use of versions.
For example, the default Python version on macOS is 2.7.16, but I don't want to replace it directly, I want to use it by switching.
At this time, pyenv is highly recommended!!

Install

The installation method is very simple. You can use the Homebrew command. For Homebrew installation, please refer to: Homebrew, a useful MAC suite management tool
The instructions are as follows

 brew install pyenv

set up

After pyenv is installed, execute the following commands for subsequent settings

 pyenv init

After the execution is completed, because zsh is used as the default shell of the terminal since the macOS Catalina version, there will be a prompt to add a line to ~/.zshrc to enable the environment variables of pyenv automatically after the system is logged in

 export PATH=“$HOME/.pyenv/bin:$PATH” eval "$(pyenv init -)"


After joining, complete the setting

Instructions

Using pyenv can easily and quickly switch Python versions, you can use the following pyenv command to query which versions of Python are currently installed on macOS

 pyenv versions

If no other version has been installed before, the terminal will respond with a result of system, which means that there is only the default version of the system.
At this time, you can use the following command to list which versions of pyenv are available for installation

 pyenv install --list

The terminal will display many python versions, then you can use the following command to install the version you want to install

 pyenv install 3.8.8

After the installation is successful, execute pyenv versions again, and you will find that 3.8.8 is added.
Then pyenv provides three ways to switch the Pyhton version

global global switch

 pyenv global 3.8.8

local current folder

 pyenv local 3.8.8

shell current terminal

 pyenv shell 3.8.8

You can use the following command to query whether the switch is successful

 python --version

end

Using pyenv, you can quickly and easily switch the python version environment without affecting the default version of macOS. It is really an artifact of Python version management.

 If you like this content, you can help me register Likecoin and help me clap five times at the bottom of the article,
Your clapping is the greatest encouragement to me, thank you! !

Link to the original text

CC BY-NC-ND 2.0

Like my work? Don't forget to support and clap, let me know that you are with me on the road of creation. Keep this enthusiasm together!