Go-Build a python development environment on Mac OS

Source: Internet
Author: User

This article was reproduced from: http://www.jb51.net/article/76931.htm

I. Installing Python

The Mac system actually comes with a Python execution environment to run Python, but development may not be enough, so we need to reinstall Python. Here are two scenarios to install:

1.homebrew

1 brew installpython

This program is relatively simple, if the error can be given to the front with sudo try, 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 whichpython

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

Two. Install Pip

Here a lot of articles said to install Easy_install first, 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 sudopython 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:

123456789 Exception:Traceback (most recent call last): ... OSError: [Errno 13] 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 PIP in the terminal 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~

Create the. Pip directory:

1 mkdir.pip

To create a pip.conf file:

1 touchpip.conf

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

12 [global]index-url = http://pypi.v2ex.com/simple

You can set the value of Index-url 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. Other module installation

1.pillow/pil

Want to use Python processing pictures, naturally without PiL this module, because PIL long-term not updated, so there is pillow this module, relying on PIL, the new version of PIP installed will come with pillow, but there seems to be no zlib module, so will error:

123456789101112 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 sudopip install-U Pillow

2.MySQLdb
Download the MySQLdb module at the following URL:

http://sourceforge.net/projects/mysql-python/
In Mac OS X directly double-click Unzip, command line into the extracted directory, execute python setup.py build

If there is

1 sh: mysql_config: commandnot found

Tip, we need to edit the path under MySQL and use vim to open the setup_posix.py

Found it:

1 mysql_config.path = "mysql_config"

Switch

1 mysql_config.path = "/usr/local/mysql/bin/mysql_config"

Then execute:

1 sudopython setup.py install

After the installation succeeds, enter Python into the Python environment at the command line, enter import MySQLdb, and report the following error in my environment:

1 >>> import   MySQLdb
1234567 traceback (most recent call L AST): &NBSP; file "<stdin>", line 1, in < Module>, &NBSP; file "mysqldb/__init__.py", Line </module><module> &NBSP; import _mysql importerror:dlopen (/library/python/2.7/site-packages/mysql_ Python-1.2.4b4-py2.7-macosx-10.8-intel.egg/_mysql.so, 2): Library not loaded:libmysqlclient.18.dylib &NBSP; referenced from:/library/python/2.7/site-packages/ mysql_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/_mysql.so &NBSP; reason:image not found

Solution, we build a soft chain on it.

1 sudoln-s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

This allows us to install the MySQLdb module in the Python environment of Mac OS X.

Go-Build a python development environment on Mac OS

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.