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
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:
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
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:
Create the. Pip directory:
To create a pip.conf file:
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 |
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:
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 |
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.
Go-Build a python development environment on Mac OS