ysoren 发表于 2018-8-5 09:23:16

Centos环境下MySQL-python安装过程

  1. 下载 MySQL-python-1.2.3.tar.gz
  地址 https://sourceforge.net/projects/mysql-python/
  2. 安装 MySQl-python
  tar xvf MySQL-python-1.2.3.tar.gz
  cd MySQL-python-1.2.3
  vi site.cfg
  把 mysql_config = /usr/local/mysql/bin/mysql_config 这一行前的#去掉,并且把mysql_config的路径设置正确。
  python setup.py build

  运行上面的命令报错如下: # python setup.pyinstall  Traceback (most recent call last):
  File "setup.py", line 5, in ?
  from setuptools import setup, Extension
  ImportError: No module named setuptools
  解决方法:
wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz  tar zxvf setuptools-0.6c11.tar.gz
  cd setuptools-0.6c11
  python setup.py build
  python setup.py install
  继续安装:
python setup.py build  python setup.py install
  运行测试:
# python  Python 2.4.3 (#1, Sep3 2009, 15:37:37)
   on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import MySQLdb
  /usr/lib64/python2.4/site-packages/MySQL_python-1.2.3-py2.4-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/lib64/python2.4/site-packages/MySQL_python-1.2.3-py2.4-linux-x86_64.egg/_mysql.pyc, but /opt/python/MySQL-python-1.2.3 is being added to sys.path
  >>>

  报出一大堆警告信息,解决办法:删除MySQL-python源目录,再测试一下: # python  Python 2.4.3 (#1, Sep3 2009, 15:37:37)
   on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import MySQLdb
  >>>
  Mysql模块终于正常了!
页: [1]
查看完整版本: Centos环境下MySQL-python安装过程