解决windows64位系统上安装mysql-python报错

2018年03月12日 13:08:24 一个CD包 阅读数:1231
 
 版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yu12377/article/details/79525470

一、 背景

python项目中需要操作mysql,于是运行:

pip install MySQL-python

报一连串的错误,前面的错误根据提示都好解决,但被下面的错误一直卡住,好一翻折腾才解决,所以在此记录以备忘。

Cannot open include file: ‘config-win.h’: No such file or directory” while installing mysql-python

二、 安装

1. 安装64位版本的python

https://www.python.org/ftp/python/2.7.14/python-2.7.14.amd64.msi

2. 安装VCForPython

去微软官网下载 
没有安装时会报如下错误:

C:\Users\admin\Desktop>pip install mysql-python
Collecting mysql-python
Using cached MySQL-python-1.2.5.zip
Installing collected packages: mysql-python
Running setup.py install for mysql-python ... error
Complete output from command c:\python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\admin\\appdata\\local\\temp\\pip-build-srpbqq\\mysql-python\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record c:\users\admin\appdata\local\temp\pip-6qgvvl-record\install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_py
creating build
creating build\lib.win-amd64-2.7
copying _mysql_exceptions.py -> build\lib.win-amd64-2.7
creating build\lib.win-amd64-2.7\MySQLdb
copying MySQLdb\__init__.py -> build\lib.win-amd64-2.7\MySQLdb
copying MySQLdb\converters.py -> build\lib.win-amd64-2.7\MySQLdb
copying MySQLdb\connections.py -> build\lib.win-amd64-2.7\MySQLdb
copying MySQLdb\cursors.py -> build\lib.win-amd64-2.7\MySQLdb
copying MySQLdb\release.py -> build\lib.win-amd64-2.7\MySQLdb
copying MySQLdb\times.py -> build\lib.win-amd64-2.7\MySQLdb
creating build\lib.win-amd64-2.7\MySQLdb\constants
copying MySQLdb\constants\__init__.py -> build\lib.win-amd64-2.7\MySQLdb\constants
copying MySQLdb\constants\CR.py -> build\lib.win-amd64-2.7\MySQLdb\constants
copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-2.7\MySQLdb\constants
copying MySQLdb\constants\ER.py -> build\lib.win-amd64-2.7\MySQLdb\constants
copying MySQLdb\constants\FLAG.py -> build\lib.win-amd64-2.7\MySQLdb\constants
copying MySQLdb\constants\REFRESH.py -> build\lib.win-amd64-2.7\MySQLdb\constants
copying MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-2.7\MySQLdb\constants
running build_ext
building '_mysql' extension
error: Microsoft Visual C++ 9.0 is required. Get it from http://aka.ms/vcpython27 ----------------------------------------
Command "c:\python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\admin\\appdata\\local\\temp\\pip-build-srpbqq\\mysql-python\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record c:\users\admin\appdata\local\temp\pip-6qgvvl-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in c:\users\admin\appdata\local\temp\pip-build-srpbqq\mysql-python\ C:\Users\admin\Desktop>
根据错误提示,访问:http://aka.ms/vcpython27 

下载相应版本的VCForPython安装,再次安装mysql-python

3. 安装mysql-connector-python-2.1.7-py2.7-windows-x86-64bit.msi

https://cdn.mysql.com//Downloads/Connector-Python/mysql-connector-python-2.1.7-py2.7-windows-x86-64bit.msi

4. 安装mysql-connector-c-6.0.2-winx64.msi

https://cdn.mysql.com//Downloads/Connector-C/mysql-connector-c-6.0.2-winx64.msi 
没有安装【mysql-connector-python】与【mysql-connector-c-6.0.2】时,会报如下错误:

C:\Users\admin\Desktop>pip install mysql-python
Collecting mysql-python
Using cached MySQL-python-1.2.5.zip
Installing collected packages: mysql-python
Running setup.py install for mysql-python ... error
Complete output from command c:\python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\admin\\appdata\\local\\temp\\pip-build-r8dkiw\\mysql-python\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record c:\users\admin\appdata\local\temp\pip-srrfzx-record\install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_py
creating build
creating build\lib.win-amd64-2.7
copying _mysql_exceptions.py -> build\lib.win-amd64-2.7
creating build\lib.win-amd64-2.7\MySQLdb
copying MySQLdb\__init__.py -> build\lib.win-amd64-2.7\MySQLdb
copying MySQLdb\converters.py -> build\lib.win-amd64-2.7\MySQLdb
copying MySQLdb\connections.py -> build\lib.win-amd64-2.7\MySQLdb
copying MySQLdb\cursors.py -> build\lib.win-amd64-2.7\MySQLdb
copying MySQLdb\release.py -> build\lib.win-amd64-2.7\MySQLdb
copying MySQLdb\times.py -> build\lib.win-amd64-2.7\MySQLdb
creating build\lib.win-amd64-2.7\MySQLdb\constants
copying MySQLdb\constants\__init__.py -> build\lib.win-amd64-2.7\MySQLdb\constants
copying MySQLdb\constants\CR.py -> build\lib.win-amd64-2.7\MySQLdb\constants
copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-2.7\MySQLdb\constants
copying MySQLdb\constants\ER.py -> build\lib.win-amd64-2.7\MySQLdb\constants
copying MySQLdb\constants\FLAG.py -> build\lib.win-amd64-2.7\MySQLdb\constants
copying MySQLdb\constants\REFRESH.py -> build\lib.win-amd64-2.7\MySQLdb\constants
copying MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-2.7\MySQLdb\constants
running build_ext
building '_mysql' extension
creating build\temp.win-amd64-2.7
creating build\temp.win-amd64-2.7\Release
C:\Users\admin\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include" -Ic:\python27\include -Ic:\python27\PC /Tc_mysql.c /Fobuild\temp.win-amd64-2.7\Release\_mysql.obj /Zl
_mysql.c
_mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory
error: command 'C:\\Users\\admin\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\amd64\\cl.exe' failed with exit status 2 ----------------------------------------
Command "c:\python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\admin\\appdata\\local\\temp\\pip-build-r8dkiw\\mysql-python\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record c:\users\admin\appdata\local\temp\pip-srrfzx-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in c:\users\admin\appdata\local\temp\pip-build-r8dkiw\mysql-python\

5. MySQL-python-1.2.5.zip

https://pypi.python.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip#md5=654f75b302db6ed8dc5a898c625e030c 
注意:没有安装【mysql-connector-python】与【mysql-connector-c-6.0.2】时:此步骤会一直报错: 
> Cannot open include file: ‘config-win.h’: No such file or directory” while installing mysql-python

注意:即使已经安装了【mysql-connector-python】与【mysql-connector-c-6.0.2】,也可能会报上面的错误

原因: pypi上提供的MySQL-python包依赖32位的mysql-connector-c-6.0.2包,因为我们前面只安装了64位的版本,所有一直找不到mysql-connector-c-6.0.2而报上面的错误

  • 解决方法一: 
    去mysql官网下载32位的mysql-connector-c-6.0.2,同时安装32位版本与64位版本,再运行: 【亲测,失败,但此方法应该可以,原因本人没有深究】
pip install mysql-python
  • 1
  • 解决方法二: 
    下载MySQL-python-1.2.5的源码,解压并修改文件【MySQL-python-1.2.5/site.cfg】,找到如下一行的路径,将其修改成如下第二行(修改引用版本,将32位指向64位),再运行python setup.py install安装【亲测通过】 (前提:安装64位的mysql-connector-c-6.0.2,)

connector = C:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2 
connector = C:\Program Files\MySQL\MySQL Connector C 6.0.2

# 源码安装
cd MySQL-python-1.2.5
python setup.py install

解决windows64位系统上安装mysql-python报错的更多相关文章

  1. 在Win8.1(64位)系统上安装Scrapy(python 2.7.7)

    为了在win8.1上安装scrapy折腾了好久,最终安装成功,总结步骤如下: 下载安装Visual C++ 2008 redistributables 安装lxml-3.2.4.win-amd64-p ...

  2. centos7.2 linux 64位系统上安装mysql

    1.在线安装mysql 在终端中命令行下输入(在官网下载mysql): # wget https://dev.mysql.com/downloads/repo/yum/mysql57-communit ...

  3. 如何在64位系统上安装SQL Server 2000

    如何在64位系统上安装SQL Server 2000? 现在用SQL Server 2000数据库的人少了吧?大都是SQL Server 2005/2008了.不过还是有需求的,今天一朋友就让我在他的 ...

  4. Linux+Redis实战教程_day02_Linux系统上安装MySQL

    Linux系统上安装MySQL 安装MySQL 卸载自带mysql 查询mysql的安装情况,可以直接使用了 rpm -qa | grep -i mysql –-color 卸载原生的MySQL rp ...

  5. python 3.5.2安装mysql驱动报错

    python 3.5.2安装mysql驱动报错 python 3.5.2安装mysql驱动时出现如下异常: [root@localhost www]# pip install mysql-connec ...

  6. 【pycharm】pycharm上安装tensorflow,报错:AttributeError: module 'pip' has no attribute 'main' 解决方法

    pycharm上安装tensorflow,报错:AttributeError: module 'pip' has no attribute 'main' 解决方法 解决方法: 在pycharm的安装目 ...

  7. Linux系统上安装MySQL(rpm)

    1.准备工作 从MySQL官网上分别下载mysql服务器端于客户端包. 如: MySQL-server-5.5.15-1.linux2.6.x86_64.rpm和MySQL-client-5.5.15 ...

  8. 【转】Linux系统上安装MySQL 5.5 rpm

    1.准备工作 从MySQL官网上分别下载mysql服务器端于客户端包. 如: MySQL-server-5.5.15-1.linux2.6.x86_64.rpm和MySQL-client-5.5.15 ...

  9. windows系统上安装mysql操作过程及常见错误处理

    1.下载mysql免安装版本,下载地址:http://dev.mysql.com/downloads/mysql/ 解压到自己的目录 2.编辑配置文件: 新建一个文本文件,修改名称及后缀为my.ini ...

随机推荐

  1. jQyery 整体架构

    jQuery的模块 一.jQuery一共有13个模块: 1. 核心方法 2. 回调模块(callbacks) 3. 数据缓存 4. 异步队列(Deffered) 5. 选择器操做 6. 属性操作 7. ...

  2. TwoSum leetcode

    class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { vector& ...

  3. cocos2dx 编译时间长问题

    { F:\cocos2dx\cocos2d-x-3.7.1\templates\cpp-template-default 彻底解决方式 为把cocos的模版项目编译好(详细是所有生成好并清理Hello ...

  4. Android开源框架ViewPageIndicator和ViewPager实现Tab导航

    前言: 关于使用ViewPageIndicator和ViewPager实现Tab导航,在开发社区里已经有一堆的博客对其进行了介绍,假设我还在这里写怎样去实现.那简直就是老生常谈,毫无新奇感,并且.我也 ...

  5. 【bzoj1821】[JSOI2010]Group 部落划分 Group

    题目大意:要求把n个点分成m块,使得每一块之间的距离的最小值最大 n^2枚举所有点之间距离 然后sort一下 并查集维护连通关系 一开始e[]开MAXN然后WA了测了4ms,然后开MAXN<&l ...

  6. 让mongodb执行js文件

    环境: Linux js代码: 循环删除表中的数据: clear-mongodb-dialog.js print('=========BEGIN=========='); for(var i of [ ...

  7. oc80--copy

    // // main.m // Copy基本使用,拷贝的本质:修改其中一个不能影响另外一个. // 每个oc对象都有copy和mutableCopy方法,前提是必须遵守NSCopying协议实现cop ...

  8. 【POJ 3614】 Sunscreen

    [题目链接] http://poj.org/problem?id=3614 [算法] 将MinSPF从大到小排序,每头牛找SPF值最大的防晒霜 [代码] #include <algorithm& ...

  9. Is the Information Reliable?(差分约束系统)

    http://poj.org/problem?id=2983 题意:给出M条信息,判断这些信息的正确性.(1)V A B :表示A,B之间的距离>=1; (2)P A B X :表示A B之间的 ...

  10. 4.28 QBXT模拟赛

    NOIP2016提高组模拟赛 ——By wangyurzee7 中文题目名称 迷妹 膜拜 换数游戏 英文题目与子目录名 fans mod game 可执行文件名 fans mod game 输入文件名 ...