How to install the MAC python

Transfer: https: //blog.csdn.net/hou_manager/article/details/79555809

A, Python Introduction

Python Introduction

Python3 officially released in 2008, December 3, but there are still a lot of library use Python2.7, so the need to install both versions of the Mac inside, and Python district and systems used to separate it? Today is how to write correctly installed the first time, and switch the default version of Python do not misuse the system.

Second, the installation

STEP 1 install Xcode

After installation is complete install Xcode command line tool

xcode-select --install

STEP 2 to install Homebrew

You can refer to the official website or directly insert:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"


STEP 3 Installing Python

The next step to officially enter the installation of the Python!
First, enter

python --version 

This is a Python Mac system you want to use, do not move it. So now we have to use Python to install homebrew own use.

Python use homebrew search

brew search python

start installation:

brew install python

 

python3 successful installation

 

 If you want to install python2, execute the following command

brew install python@2

It represents the successful installation of python

 

Check the installation directory

open /usr/local/Cellar

 

STEP 4 route setting the PATH $ (without interference and system Python)

What is the path to $ PATH it?

Remember when we installed Python, enter the brew,
the system will automatically know to begin to run homebrew.
The system in the end how to know where we brew in?
This is the purpose of the $ PATH!

echo $PATH

 


as the picture shows

 

Semi-colon (:) is the separator means
so when you enter the brew when the terminal inside
the system will start from / usr / bin to start looking
if found in / usr / bin, then there
will be a down / bin to search, and so on

Now, we return to the folder to see the
brew in fact, in / usr / local / bin inside

 

So the question is, the system in / usr / bin and there was a Python
now we are in / usr / local / Cellar which also installed Python
so that when the terminal marked with the python command, who would it be open?
Because sequential path, it will first find the system Python
'm going to solve this problem

sudo emacs /etc/paths

Let's get administrator privileges sudo
with the emacs editor program file path
terminal will be asked to enter a password

 

If this is not the order, adjusted to this order.

control + k: the cut out word line
control + y: Paste the word
control + x + s: Save
control + x + c: turn off emacs

Then, restart the terminal will see the change, call back

echo $PATH

STEP 5 the installation is completed, the check result

这样就完成啰!
其实python3本身比较不会跟其他人打架 

Guess you like

Origin www.cnblogs.com/abella/p/10994299.html