Build a Python environment on a Mac

Source: Internet
Author: User

First Respect Original: http://blog.justbilt.com/2014/07/02/setup_python_on_mac/

build a Python environment on a Mac

This two days to recreate the environment of Python, found that many places are still easy to forget, so have this article, later convenient to view. one. Install Python

Mac systems actually bring a python execution environment to run Python, but development may not be enough, so we need to reinstall Python. Here are two scenarios for installation:

1.homebrew

1
Brew Install Python

This is a simpler scenario, and if you make a mistake, you can try the previous sudo, which may not be the latest version of Python.

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

The two methods of installing the Python location are not the same, you can use:

1
which Python

To view the installation location. After installation, type Python in the terminal to verify that the installation was successful. two. Install Pip

Here a lot of articles said to first install Easy_install, in fact, is not necessary. 1. We first get the PIP setup script:

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 is OK. 2. Install PIP

1
sudo python get-pip.py

Use Python to execute the script you just obtained, where sudo can choose to use, and if you encounter an error like this you must add sudo:

1
2
3
4
5
6 7 8 9
Exception:

Traceback (most recent call last):

...

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 the installation is successful, you can type PIP in the terminal to detect it, and try again if you do not restart the terminal. 3. Modify the PIP source

In China, because of the Kungfu network, using PIP to install some modules will be particularly slow or even can not 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 ~

Create the. 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 now use the source of the time V2ex, so add:

1
2
[Global]
Index-url = Http://pypi.v2ex.com/simple

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

The PIP source has been modified so that it will be downloaded from this source when you install the module using the PIP, and you can test it yourself. three. Other modules installation 1.pillow/pil

Want to use Python processing pictures, natural PIL This module, because PIL has not been updated for a long time, so there is pillow this module, depending on the PIL, the new version of the PIP will be installed after the pillow, but there seems to be no zlib module, so will be an error:

1
2
3
4 5 6 7 8
9
ten
-one 12
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 190, in load

    d = Image._getdecoder (Self.mode, D, A, self.decoderconfig)

  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 
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.