安装mysql-python

碰到的问题
1、ImportError
原因是我的环境变量PYTHONHOME指定的路径不正确,导致无法导入相应模块
2、python setup.py install
line 7, in get_config     serverKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, options['registry_key']) WindowsError: [Error 2]
这个原因是因为我是解压包安装的mysql,在注册表中没有对一个的项。
具体可以查看site.cfg文件中registry_key对应的值
解决办法:
在注册表中添加对应的项
HKEY_LOCAL_MACHINE/SOFTWARE/MySQL AB/MySQL Server 5.0
版本不是5.0的修改为对应的版本值。
并新建Location和Version项,Location指定值为mysql的安装路径。
或者
注释掉行mysql_root, dummy = _winreg.QueryValueEx(serverKey,'Location')
修改为:mysql_root=r"mysql的安装路径"
3、安装c/c++ 编译器
MySQL-python-1.2.3c1>setup.py install
running install
running bdist_egg
running egg_info
writing MySQL_python.egg-info\PKG-INFO
writing top-level names to MySQL_python.egg-info\top_level.txt
writing dependency_links to MySQL_python.egg-info\dependency_links.txt
reading manifest file 'MySQL_python.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'MySQL_python.egg-info\SOURCES.txt'
installing library code to build\bdist.win32\egg
running install_lib
running build_py
copying MySQLdb\release.py -> build\lib.win32-2.6\MySQLdb
running build_ext
building '_mysql' extension
error: Unable to find vcvarsall.bat
安装mingw32,可以参考另一篇文章
4、找不到相应的头文件
>python setup.py build --compiler=mingw32
running build
running build_py
copying MySQLdb\release.py -> build\lib.win-amd64-2.7\MySQLdb
running build_ext
building '_mysql' extension
D:\dev\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -ID:\mysql\incl
ude -ID:\dev\Python27\include -ID:\dev\Python27\PC -c _mysql.c -o build\temp.win-amd64-2.7\Release\_mysql.o /Zl
gcc: /Zl: No such file or directory
_mysql.c:34:24: fatal error: config-win.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
安装mysql-connector-c

你可能感兴趣的:(c,mysql,python,ext,gcc)