MAC uses kit management tool homebrew to install python2.7 and Python3 correctly at the same time

Source: Internet
Author: User

MAC OSX is correctly installed with PYTHON 2.7 and PYTHON3

Python3 has come out (it has been out for a long time, dizzy)!
But there are still many libraries that use Python2.7, so how do you install the two versions in your Mac and separate them from the Python area used by the system? Today's writing is how to properly install it for the first time, and switch to the preset version, not the wrong Python for the system.

It's just a couple of steps, and it's not going to be too hard (or maybe you're just going to have it installed)

STEP 1 Installation XCODE

You can search for Xcode and install it in the APP Store

After the installation, open Xcode.
The first time you open it, you'll need to agree with his License agreement.
Then go to terminal and install the Xcode command line tool:

Xcode-Select -install

Install Xcode to the end of this, to enter the next step!

STEP 2 Installation Kit management tool: HOMEBREW

You can go to the official website or paste it in terminal:

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

You can run after the installation.

Brew Doctor

If the

Your system is ready to brew.

On behalf of everything OK, if there is Warning, also don't worry too much, you can follow the steps to fix it!
If there is a Warning, though you will see a sentence

If everything you use Homebrew for is working fine:please don ' t worry and just ignore them.

But it is also suggested that you install things well, and that it is not time to forget what you really are.

STEP 3 Installation PYTHON

Next step is to formally enter the installation of Python!
First, enter

Python --version

Oh, my God! has not yet started Python, how has the computer been there?
This is the Python that the MAC system uses, so it's not always good to be chaotic!
So now we're going to use homebrew to install the usual. ) used by Python.

Search Python with Homebrew

Brew Search python

At this point, you'll see Python and Python3.
Because I have already installed, so the side will write (installed).

To install Python!

Brew Install python

This is the beginning of the installation.
After the installation, enter

Brew Install python3

When installed, Python will be installed in

/usr/local/cellar

Then look at this folder (or shift+command+g input path)

Open /usr/local/Cellar/


You can see that the Python you are installing is now out there!
In addition to Python, it is possible to install something else, such as SQLite.
Always, don't worry too much, homebrew will take care of himself.
(Because I'm a lot of miles copied copied, so you might not have so much in your folders)

STEP 4 Set Path $PATH (no fight with the system PYTHON)

What is the path $PATH?

Remember when we were in Python, we entered Brew,
The system will automatically know to start running homebrew.
How does the system know where our brew is?
This is the purpose of $PATH!

Echo $PATH

Then you'll see a bunch of things like this.

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

Score (:) is the meaning of separation
So when you enter brew in terminal,
The system will start looking for/usr/bin.
If you can't find it in/usr/bin,
Will go down a/bin to search, and push

Now, we go back to the folder to see
Brew is actually in the/usr/local/bin!

So the question now is that the system has a Python in/usr/bin.
Now we have Python in/usr/local/cellar.
So who's going to be open when terminal a python command?
Because the path is sequential, it will first find the system Python
Now we're going to solve this problem.

sudo emacs /etc/paths

sudo allows us to get admin privileges
Edit the path file with the Emacs program
Terminal will ask to enter the password
(That is, the password that you need to enter in your normal installation)

Now we're going to move the/usr/local/bin to the top.
Control + K: Cut a line of words
Control + y: Put the words on the stickers
Control + x + S: Archive
CONTROL + x + C: get rid of Emacs

This time, one more call.

Echo $PATH

Why hasn't it changed!?
Because to open a new terminal will update Yo!
Open the new window and enter it again and you'll see the results we just modified.

STEP 5 Complete! Confirm the installation Results ~

This is done!
Actually, Python3 is not going to fight with the others.
Because he is the python3 of independence.
So we're mainly trying to make sure that we read our brew python

which python

At this time to see

/usr/local/bin/python

Let's take a look at Python3.

which Python3

should be

/usr/local/bin/python3

The representative read the python that was just installed!
Of course if you're going to run the system itself python
(should not be used to ~)
Just enter

/usr/bin/python

The thing is ... It's done!

Reprinted from Https://stringpiggy.hpd.io/mac-osx-python3-dual-install/

MAC uses kit management tool homebrew to install python2.7 and Python3 correctly at the same time

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.