Build a Python Development Environment on Mac OS,

Source: Internet
Author: User

Build a Python Development Environment on Mac OS,

1. Install python

The mac system actually comes with a python execution environment to run python, but it may not be enough for development. Therefore, we need to reinstall python. There are two solutions for installation:

1. homebrew

brew install python

This solution is relatively simple. If an error occurs, you can add sudo to the previous step. This python installation may not be the latest version.

2. Download and install from the official website
You can use.

The location of python installed in these two methods is different. You can use:

which python

To check the installation location. After the installation is complete, type python in the terminal to verify whether the installation is successful.

Ii. Install pip

Install easy_install in many articles.

1. Obtain the pip installation script first:

wget https://bootstrap.pypa.io/get-pip.py

If wget is not installed, you can copy all the content here, create a new get-pip.py file, copy the content to OK.

2. Install pip

sudo python get-pip.py

Run the obtained script in python. sudo can be used here. If this error is similar, you must add sudo:

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 the installation is successful, you can enter pip in the terminal to check whether the device can be restarted.

3. Modify pip Source

In tianchao, due to the reasons of kung fu network, installing some modules using pip will be very slow or even unable to download. Therefore, we need to modify the pip source to some domestic image addresses, thank you very much for your selfless dedication ~

First, go to the HOME path:

cd ~

Create the. pip directory:

mkdir .pip

Create the pip. conf file:

touch pip.conf

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

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

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

Now, the pip source is successfully modified, and the module will be downloaded and installed from this source later. You can test it on your own.

Iii. Installation of other modules

1. Pillow/PIL

To use python to process images, the PIL module is indispensable. Because PIL has not been updated for a long time, the module Pillow depends on PIL. The new version of pip comes with Pillow after installation, but it seems that there is no zlib module, so an error will be reported:

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

Therefore, we need to manually reinstall:

sudo pip install -U Pillow

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

Http://sourceforge.net/projects/mysql-python/
On mac OS x, double-click to decompress the package. Run the command line to enter the decompressed directory and run python setup. py build.

If

sh: mysql_config: command not found

Note: We need to edit the mysql path and use vim to open setup_posix.py.

Find:

mysql_config.path = "mysql_config"

Changed:

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

Then execute:

sudo python setup.py install

After the installation is successful, enter python in the command line to enter the python environment and import MySQLdb. the following error is reported in my environment:

>>> import MySQLdb
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "MySQLdb/__init__.py", line 19, in </module><module> import _mysqlImportError: 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 can build a soft chain.

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

In this way, we have installed the MySQLdb module in the python environment of mac OS x.

Articles you may be interested in:
  • Tutorial on installing Python Pillow library on Mac OS
  • Steps for upgrading to Python3.3 for Mac OS X10.9 Installation
  • Use mod_wsgi on Mac OS to connect Python to Apache server

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.