Build a python development environment on Mac OS

Source: Internet
Author: User

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 Install Python

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 which Python

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

?

1 2 3 4 5 6 7 8 9 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 FAI Lure 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 Touch pip.conf

You can use your favorite editor to open the pip.conf file, I am now using the V2ex source, 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.

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:

?

1 2 3 4 5 6 7 8 9 10 11 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, load d = Image._getdecoder (Self.mode, D, A, self.decoderconfig) File"/L ibrary/python/2.7/site-packages/pil/image.py ", line 389, in _getdecoder raise IOError (" decoder%s not available "% decod Er_name) Ioerror:decoder Zip not available

So we need to reinstall manually:

?

1 sudo pip 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:command not 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 sudo python 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

?

1 2 3 4 5 6 7 Traceback (most recent): File ' <stdin> ', line 1, in <module> file ' mysqldb/__init__.py ', line +, in </module><module> 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 Referenced from :/library/python/2.7/site-packages/mysql_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/_mysql.so Reason:image not Found

Solution, we build a soft chain on it.

?

1 sudo ln-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.

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.