Build a Python environment on your Mac

Source: Internet
Author: User

I. Installing Python

In fact, the Mac comes with Python enough, this step can be skipped. –by Bin

The Mac system comes with a python execution environment, but in order to get the latest version of Python, we need to reinstall Python. Here are two scenarios to install:

1.homebrew

1
Brew Install Python

This program is relatively simple, if the error can be given before the test sudo , this installation of Python may not be the latest version.

2. Download and install from official website
We can download and install the latest version of Python from Https://www.python.org/download, installation is not brain, all the way down OK, the disadvantage is to upgrade later, uninstall have to maintain their own.

The location of the python installed by these two methods is not the same, you can use:

1
which Python

To view the installation location. After the installation is complete, type in the terminal python to verify that the installation was successful.

Two. Install Pip

Here are a lot of articles said to install first easy_install , in fact, it is not necessary.

1. We get the PIP installation script first:
1
wget https://bootstrap.pypa.io/get-pip.py

If there is no installation wget can go here to copy all the content, create a new get-pip.py file, the content copied into the OK.

2. Install Pip
1
sudo python get-pip.py

Use Python to execute the script just obtained, here sudo can choose to use, if you encounter a similar error, you must add sudo:

Exception:traceback (most recent): ... OSError: [Errno] Permission denied: ' xxx/pip-0.7.2-py2.7.egg/egg-info/dependency_links.txt ' storing debug log for Failure In/users/bilt/.pip/pip.log

After successful installation, you can type in the terminal pip to detect, if not restart the terminal after the attempt.

3. Modifying the PIP source

In China, because of the Kung Fu Network, using PIP to install some modules will be particularly slow or even unable to download, so we need to modify the source of the PIP to some of the domestic mirror address, especially thanks to the domestic selfless dedication of the Organization ~

First go to the home path:

1
CD ~

To create a .pip directory:

1
mkdir. Pip

To create a pip.conf file:

1
Touch pip.conf

You can use your favorite editor to open the pip.conf file, I am now using the V2ex source, so add:

[Global]index-url = Http://pypi.v2ex.com/simple

You can index-url set the value to the address of your actual source.

At this point the PIP source modified successfully, later using the PIP installation module will be downloaded from this source to install, you can test it yourself.

Three. Installation of other modules 1. Pillow/pil

Want to use Python processing pictures, naturally PIL This module, because PIL has not been updated for a long time, so with Pillow this module, depending on the PIL, the new version of the pip installation will come with pillow, but there seems to be no zlib module, so will error:

File "/library/python/2.7/site-packages/pil/image.py", line 1105, in Paste    im.load ()  file "/library/python/ 2.7/site-packages/pil/imagefile.py ", line, load    d = Image._getdecoder (Self.mode, D, A, self.decoderconfig) C8/>file "/library/python/2.7/site-packages/pil/image.py", line 389, in _getdecoder    raise IOError ("decoder%s not Available "% decoder_name) Ioerror:decoder zip not available

So we need to reinstall manually:

1
sudo pip install-u Pillow

Finish

Transferred from: http://blog.justbilt.com/2014/07/02/setup_python_on_mac/

Build a Python environment on your Mac

Related Article

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.