CentOS: pip install MySQL-python – InstallationError

Автор: | 31/07/2014
 

centos-logo-new-4

При установке модуля MySQLdb на:

# cat /etc/redhat-release
CentOS release 6.5 (Final)

С использованием pip:

# pip -V
pip 1.3.1 from /usr/lib/python2.6/site-packages (python 2.6)

pip сообщил об ошибке:

# pip install MySQL-python

creating build/temp.linux-x86_64-2.6

gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fe
xceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/usr/include/python2.6 -c _mysql.c -o build/temp.linu
x-x86_64-2.6/_mysql.o -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC -DUNIV_LINUX -DUNIV_LINUX

_mysql.c:29:20: error: Python.h: No such file or directory

_mysql.c:40:26: error: structmember.h: No such file or directory

_mysql.c:44:23: error: my_config.h: No such file or directory

...

Command /usr/bin/python -c "import setuptools;__file__='/tmp/pip-build-root/MySQL-python/setup.py';exec(compile(open(__file__).read().replace('rn', 'n'), __file__, 'exec'))" install --record /tmp/pip-DdlesA-record/install-record.txt --single-version-externally-managed failed with error code 1 in /tmp/pip-build-root/MySQL-python

Exception information:
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/pip/basecommand.py", line 139, in main
status = self.run(options, args)
File "/usr/lib/python2.6/site-packages/pip/commands/install.py", line 271, in run
requirement_set.install(install_options, global_options, root=options.root_path)
File "/usr/lib/python2.6/site-packages/pip/req.py", line 1185, in install
requirement.install(install_options, global_options, *args, **kwargs)
File "/usr/lib/python2.6/site-packages/pip/req.py", line 592, in install
cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
File "/usr/lib/python2.6/site-packages/pip/util.py", line 662, in call_subprocess
% (command_desc, proc.returncode, cwd))
InstallationError: Command /usr/bin/python -c "import setuptools;__file__='/tmp/pip-build-root/MySQL-python/setup.py';exec(compile(open(__file__).read().replace('rn', 'n'), __file__, 'exec'))" install --record /tmp/pip-DdlesA-record/install-record.txt --single-version-externally-managed failed with error code 1 in /tmp/pip-build-root/MySQL-python

Для решения проблемы – устанавливаем дополнительных два пакета:

# yum -y install python-devel mysql-devel

И ещё раз запускаем:

# pip install MySQL-python
Downloading/unpacking MySQL-python
Running setup.py egg_info for package MySQL-python
Installing collected packages: MySQL-python
Running setup.py install for MySQL-python
building '_mysql' extension
...
/usr/include/python2.6/pyconfig-64.h:808:1: warning: this is the location of the previous definition
gcc -pthread -shared build/temp.linux-x86_64-2.6/_mysql.o -L/usr/lib64/mysql -L/usr/lib64 -lmysqlclient_r -lz -lpthread -lcrypt -lnsl -lm -lpthread -lssl -lcrypto -lpython2.6 -o build/lib.linux-x86_64-2.6/_mysql.so
Successfully installed MySQL-python
Cleaning up...

Готово.