linux -CentOS release 安装python2.73 支持mysql模块

linux -CentOS release 安装python2.73

如果觉得网速还行,又怕麻烦,可以直接如下安装yum groupinstall -y 'Development Libraries‘,可以省去很多麻烦因为机器的默认安装包选的不通,所以建议大家安装此步。

如果网速一般,可以按下面的安装,遇到问题,可以参看后面的错误解决方式。

此处安装需要的基本支持包

yum install -y ncurses-devel
yum install zlib-devel    zlib  -y;
yum install -y mysql mysql-devel;

此处安装Python-2.7.3
tar xf Python-2.7.3.tar
cd Python-2.7.3;
./configure;
make (此处执行后切记查看,返回信息如果和本文最下面的返回信息相同,则可以继续编译,否则需要补全。)
make install;

python 登录下查看是否为2.7版本。是则继续。否则查看错误。

此处安装setuptools-0.6c11.tar  ,编译和安装后面的程序需要用到。
tar xf setuptools-0.6c11.tar
cd setuptools-0.6c11;
python setup.py install;


此处2选1
 1.easy_install MySQL-python

 2.tar xf MySQL-python-1.2.3.tar

    cd MySQL-python-1.2.3;
    python setup.py build;
    python setup.py install;
此处登录python查看版本,并验证是否可以正常导入mysql模块。
python;
import MySQLdb
如果不报错,返回如下即可

[root@bogon MySQL-python-1.2.3]# python
Python 2.7.3 (default, Jun 18 2013, 10:49:14)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
/usr/local/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/local/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg/_mysql.pyc, but /usr/local/src/MySQL-python-1.2.3 is being added to sys.path
>>>

至此 就大功告成了。

如果报错,则需要添加模块,(如果你和我一样是默认安装的就不需要添加,如果你指定了安装目录就需要)

echo /usr/local/mysql/lib/mysql/ >>/etc/ld.so.conf

ldconfig

 

其中安装的时候遇到的问题,安装后特地分享出来,避免大家也是半天找不到问题。

如果安装python2.73(./configure;make )

发现make 后 返回信息如下,需要注意。

[root@bogon Python-2.7.3]# make
running build
running build_ext
INFO: Can't locate Tcl/Tk libs and/or headers

Python build finished, but the necessary bits to build these modules were not found:
_bsddb             _sqlite3           _tkinter       
bsddb185           bz2                dbm            
dl                 gdbm               imageop        
readline           sunaudiodev                       
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

running build_scripts

解决方式就是安装文章开头的补丁包,yum groupinstall -y'Development Libraries'

[xxx@xxx]#python setup.py install
..........中间的省略
src/pycurl.c:3777: error: ‘CURLSSH_AUTH_HOST’ undeclared (first use in this function)
src/pycurl.c:3778: error: ‘CURLSSH_AUTH_KEYBOARD’ undeclared (first use in this function)
src/pycurl.c:3779: error: ‘CURLSSH_AUTH_DEFAULT’ undeclared (first use in this function)
src/pycurl.c:3788: error: ‘CURLINFO_APPCONNECT_TIME’ undeclared (first use in this function)
src/pycurl.c:3804: error: ‘CURLINFO_REDIRECT_URL’ undeclared (first use in this function)
src/pycurl.c:3805: error: ‘CURLINFO_PRIMARY_IP’ undeclared (first use in this function)
src/pycurl.c:3825: error: ‘CURL_CSELECT_IN’ undeclared (first use in this function)
src/pycurl.c:3826: error: ‘CURL_CSELECT_OUT’ undeclared (first use in this function)
src/pycurl.c:3827: error: ‘CURL_CSELECT_ERR’ undeclared (first use in this function)
error: Setup script exited with error: command 'gcc' failed with exit status 1

此处报错找了半天最后的解决方式是

yum install -y mysql mysql-devel

为了测试 mysql模块是否可以使用我们需要测试:

[root@bogon src]# python
Python 2.7.3 (default, Jun 17 2013, 14:30:25)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb;
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named MySQLdb

此处报错找了半天最后的解决方式是  没有安装mysql的模块

可以选择 用    easy_install MySQL-python
或是自己下载源码包编译:

[root@bogon src]# cd MySQL-python-1.2.3;
[root@bogon MySQL-python-1.2.3]# python setup.py build
Traceback (most recent call last):
  File "setup.py", line 5, in <module>
    from setuptools import setup, Extension
ImportError: No module named setuptools

如果报这个错误,就说明你没有安装最新的setuptools

解决方式:

tar xf setuptools-0.6c11.tar

cd setuptools-0.6c11

python setup.py install   (此处用什么版本的python 安装 就会生成什么版本的setuptools  所以最好确定当前的python是新的2.73版本。)

如果报错:

creating 'dist/setuptools-0.6c11-py2.7.egg' and adding 'build/bdist.linux-x86_64/egg' to it
Traceback (most recent call last):
  File "setup.py", line 94, in <module>
    scripts = scripts,
  File "/usr/local/lib/python2.7/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/usr/local/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/local/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/local/src/setuptools-0.6c11/setuptools/command/install.py", line 76, in run
    self.do_egg_install()
  File "/usr/local/src/setuptools-0.6c11/setuptools/command/install.py", line 96, in do_egg_install
    self.run_command('bdist_egg')
  File "/usr/local/lib/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/usr/local/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/local/src/setuptools-0.6c11/setuptools/command/bdist_egg.py", line 236, in run
    dry_run=self.dry_run, mode=self.gen_header())
  File "/usr/local/src/setuptools-0.6c11/setuptools/command/bdist_egg.py", line 527, in make_zipfile
    z = zipfile.ZipFile(zip_filename, mode, compression=compression)
  File "/usr/local/lib/python2.7/zipfile.py", line 681, in __init__
    "Compression requires the (missing) zlib module"
RuntimeError: Compression requires the (missing) zlib module

解决:这个问题 的解决方式就是

yum install -y ncurses-devel
yum install zlib-devel    zlib  -y;

然后重新安装python2.73   (./configure ;make;make install)

如果以上几种方式  尝试了很多次,还是有问题,那么只能用绝招了,(很肯能是系统安装的时候lib库没安装全)

yum groupinstall -y 'Development Libraries‘

 

如果报错:cd MySQL-python-1.2.3

[root@bogon MySQL-python-1.2.3]# python setup.py build
sh: mysql_config: command not found
Traceback (most recent call last):
  File "setup.py", line 15, in <module>
    metadata, options = get_config()
  File "/usr/local/src/MySQL-python-1.2.3/setup_posix.py", line 43, in get_config
    libs = mysql_config("libs_r")
  File "/usr/local/src/MySQL-python-1.2.3/setup_posix.py", line 24, in mysql_config
    raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found

此处报错找了半天最后的解决方式是

yum install -y mysql mysql-devel

 

 

我因为是最简系统安装,所以安装的时候遇到很多问题,安装后查看下,给大家借鉴。

[root@bogon ~]# yum grouplist
Loaded plugins: fastestmirror, security
Setting up Group Process
Loading mirror speeds from cached hostfile
 * addons: mirrors.btte.net
 * base: mirrors.btte.net
 * extras: mirrors.btte.net
 * updates: mirrors.btte.net
Installed Groups:
   Development Libraries
   Development Tools
   Dialup Networking Support
   Editors
   Mail Server
   MySQL Database
   Network Servers
   System Tools
   Yum Utilities

安装成功后,进入python的源码包目录.configure ;make,返回的信息如下,如果返回不是这个,直接执行本文开头的yum groupinstall  即可。
Python build finished, but the necessary bits to build these modules were not found:
_tkinter           bsddb185           dl             
imageop            sunaudiodev                       
To find the necessary bits, look in setup.py in detect_modules() for the module's name.


Failed to build these modules:
_sqlite3                                             

running build_scripts

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值