易截截图软件、单文件、免安装、纯绿色、仅160KB

Python安装MySQLDb模块的种种问题及解决


我的环境是:Linux version 2.4.21-4.EL
(bhcompile@daffy.perf.redhat.com) (gcc version 3.2.3 20030502 (Red Hat
Linux 3.2.3-20)) #1 Fri Oct 3 18:13:58 EDT 2003 + Python2.6.4
本文结合我安装时候的问题,总结而成
用户目录如/home/liuguanyu/ , 保证用户有root权限
1,看看有没有安装
   进入python的命令行,输入 import MySQLdb 如果没有报错,证明此模块已经安装,可以跳过以下步骤。
2,切换到用户目录/home/liuguanyu,去下载最新的MySQLdb安装包:我下载的是MySQL-python-1.2.3c1.tar.gz 。这一步所有命令集如下:
   wget -O python-1.2.3c1.tar.gz  http://cdnetworks-kr-1.dl.sourceforge.net/project/mysql-python/mysql-python-test/1.2.3c1/MySQL-python-1.2.3c1.tar.gz
   tar xzvf python-1.2.3c1.tar.gz  
   cd MySQL-python-1.2.3c1
   python setup.py build
3,出现报错:ImportError: No module named setuptools
4,回到用户目录/home/liuguanyu,安装setuptools,我安装的是setuptools-0.6c8 ,这一步的所有命令集如下:
   wget -O setuptools-0.6c8.tar.gz  http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c8.tar.gz
   tar xzvf setuptools-0.6c8.tar.gz
   cd setuptools-0.6c8
   python setup.py build
   sudo python setup.py install
5,回到用户MySQLdb源码目录
6,运行 python setup.py build
7,报错:mysql_config not found
8,上一步报错因为mysql_config命令没有找到。
9,使用whereis mysql命令找到mysql安装目录,假设mysql安装在/usr/local/mysql
10, 回到MySQLdb源码目录.
11, vi setup_posix.py 或 vim
setup_posix.py打开配置文件。此时,找到mysql_config.path
一行,把路径前面加上第9步的mysql安装路径,bin目录。即mysql_config.path =
"/usr/local/mysql/bin/mysql_config"
12, 再次运行 python setup.py build
13, 报错 /usr/bin/ld: cannot find -lmysqlclient_r
14, 切换到root用户,执行
    echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
#请主意这个/etc/ld.so.conf,这个是ld的默认配置文


相关文档:

Python 使用C代码——swig

Ref : http://www.swig.org/translations/chinese/tutorial.html
假设你有一些c你想再加Python.。举例来说有这么一个文件example.c
 /* File : example.c */
 #include <time.h>
 double My_variable = 3.0;
 int fact(int n) {
     if (n <= 1) return 1;
&nbs ......

example of python operator overloadind

And last here is the overload operators example:
# map() takes two (or more) arguments, a function and a list to apply the function to
# lambda can be put anywhere a function is expected
# map() calls lambada for every element in the self list
# since Vector has overloaded __getitem__ and __len_ ......

python算法实践3 冒泡排序

#冒泡排序
def BubbleSort(mylist):
n = len(mylist)
i = 0
j = 0
bExchange = False
for i in range(1, n):
bExchange = False
j = n - 1
while j >= i:
if mylist[j] < mylist[j - 1]:
tmp = mylist[j]
myli ......

python算法实践4 快速排序

#快速排序
def Partition(mylist, low, high):
tmp = mylist[low]
while low < high:
while low < high and mylist[high] >= tmp:
high = high - 1
if low < high:
mylist[low] = mylist[high]
low = low + 1
while low < hi ......

Python 字典使用例子


#!/usr/bin/env python
#coding=utf-8
def buildConnectionString(params):
    return ":".join(["%s=%s" %(k, v) for k, v in params.items()])
if __name__ == "__main__":
    myParams = {"server":"mpilgrim", \
               &nbs ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号