zoukankan      html  css  js  c++  java
  • Python的MySQLdb模块安装

    mysql:直接apt-get安装的,version:5.1.62

    到官方下载MySQL for Python

    然后解压,打开README:

    里面有安装过程:

      $ tar xfz MySQL-python-1.2.1.tar.gz 
      $ cd MySQL-python-1.2.1 
      $ # edit site.cfg if necessary 
      $ python setup.py build 
      $ sudo python setup.py install

    不过在python setup.py build时报错:

    ImportError: No module named setuptools

    ubuntu下安装:

    sudo apt-get install python-setuptools
    
    python-setuptools : Python Distutils Enhancements (setuptools compatibility)

    然后再次python setup.py build,又报错:

    EnvironmentError: mysql_config not found
    
    因为mysql_config是属于MySQL开发用的文件,而使用apt-get安装的MySQL是没有这个文件的,于是在包安装器里面寻找
    
    sudo apt-get install  libmysqld-dev
    
    libmysqld-dev : MySQL embedded database development files

    再次运行python setup.py build,报错:

    building ‘_mysql’ extension 
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,3,’final’,0) -D__version__=1.2.3 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-i686-2.7/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -DUNIV_LINUX -DUNIV_LINUX 
    In file included from _mysql.c:29:0: 
    pymemcompat.h:10:20: fatal error: Python.h: No such file or directory

    解决方案,

    sudo apt-get install python-dev
    
    python-dev : header files and a static library for Python (default)

    然后就按照README里的:

      $ python setup.py build 
      $ sudo python setup.py install

    测试:

    >>>import MySQLdb

    没有报错即可。

  • 相关阅读:
    C/C++中volatile关键字详解(转)
    Spring中 @Autowired标签与 @Resource标签 的区别(转)
    [转]各种互斥量的总结
    nginx限制ip访问(转)
    HDU 4833 Best Financing (DP)
    HDU 4832 Chess (DP)
    HDU 4831 Scenic Popularity
    POJ 2155 Matrix (二维线段树)
    POJ 2155 Matrix (二维树状数组)
    HDU 4819 Mosaic (二维线段树)
  • 原文地址:https://www.cnblogs.com/shangzekai/p/4435540.html
Copyright © 2011-2022 走看看