Install MySQLdb module of Python on Solaris/Solaris 10上安装Python的MySQLdb模块

Reason: Solaris 10 自带的python是forte c++编译的,所以和gcc编译的软件一起工作会有很多问题。The built-in python of Solaris 10 is compiled by forte c++, normally we want to use gcc as the default compiler. This will cause some errors:

 

root@felix1 [/data1/soft/MySQL-python-1.2.4] # python setup.py build
running build
running build_py
copying MySQLdb/release.py -> build/lib.solaris-2.10-i86pc-2.6/MySQLdb
running build_ext
building ‘_mysql’ extension
creating build/temp.solaris-2.10-i86pc-2.6
/usr/lib/python2.6/pycc -DNDEBUG -KPIC -Dversion_info=(1,2,4,’final’,1) -D__version__=1.2.4 -I/opt/mysql/include -I/usr/include/python2.6 -c _mysql.c -o build/temp.solaris-2.10-i86pc-2.6/_mysql.o -g
gcc: unrecognized option `-KPIC’
In file included from _mysql.c:44

 

为了避免该问题我们可以需要使用全都用gcc编译的软件一起工作。包括python和mysql。To avoid this we need to use a python which compiled by GCC. We need a mysql compiled by GCC as well. Download python from www.sunfreeware.com and download 32bit mysql from mysql.com and install them.

从sourceforge上下载MySQLdb模块源代码,设置环境变量/Download MySQLdb from sf.net and setup the environment:

 

root@felix1 [/data1/soft/MySQL-python-1.2.4] # export LD_LIBRARY_PATH=/usr/local/mysql/lib:/opt/mysql/lib:/lib:/usr/lib:/usr/local/lib:/usr/local/mysql/lib
root@felix1 [/data1/soft/MySQL-python-1.2.4] # PATH=/usr/local/mysql/bin:$PATH
root@felix1 [/data1/soft/MySQL-python-1.2.4] # python setup.py build

running build
running build_py
copying MySQLdb/release.py -> build/lib.solaris-2.10-i86pc-2.6/MySQLdb
running build_ext
building ‘_mysql’ extension
gcc -shared build/temp.solaris-2.10-i86pc-2.6/_mysql.o -L/usr/local/mysql/lib -lmysqlclient_r -lthread -lsocket -lnsl -lm -lrt -o build/lib.solaris-2.10-i86pc-2.6/_mysql.so

root@felix1 [/data1/soft/MySQL-python-1.2.4] # python setup.py install

你就会安装MySQLdb模块到/usr/local下的python了。此时因为_mysql.so已经编译完成,所以就算你切换回系统python,执行python setup.py install,也会得到一个正确的安装的模块。
You’ll install the module to python under /usr/local. Now the _mysql.so is built, so even you switch to the /usr/bin/python, execute ‘python setup.py install’, you’ll get a good module as well

 

Leave a Reply

Your email address will not be published. Required fields are marked *