pip在Windows 10,Python 3.5上安装MySQL-python?

时间:2016-04-03 05:25:09

标签: python mysql django windows

当我尝试在Windows 10上安装pip install MySQL-python时,我得到了:

C:\Users\ghina>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:\python35\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\ghina\\AppData\\Local\\Temp\\pip-build-eo59erqx\\MySQL-python\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\ghina\AppData\Local\Temp\pip-b4pe3d_p-record\install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-3.5
    copying _mysql_exceptions.py -> build\lib.win-amd64-3.5
    creating build\lib.win-amd64-3.5\MySQLdb
    copying MySQLdb\__init__.py -> build\lib.win-amd64-3.5\MySQLdb
    copying MySQLdb\converters.py -> build\lib.win-amd64-3.5\MySQLdb
    copying MySQLdb\connections.py -> build\lib.win-amd64-3.5\MySQLdb
    copying MySQLdb\cursors.py -> build\lib.win-amd64-3.5\MySQLdb
    copying MySQLdb\release.py -> build\lib.win-amd64-3.5\MySQLdb
    copying MySQLdb\times.py -> build\lib.win-amd64-3.5\MySQLdb
    creating build\lib.win-amd64-3.5\MySQLdb\constants
    copying MySQLdb\constants\__init__.py -> build\lib.win-amd64-3.5\MySQLdb\constants
    copying MySQLdb\constants\CR.py -> build\lib.win-amd64-3.5\MySQLdb\constants
    copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-3.5\MySQLdb\constants
    copying MySQLdb\constants\ER.py -> build\lib.win-amd64-3.5\MySQLdb\constants
    copying MySQLdb\constants\FLAG.py -> build\lib.win-amd64-3.5\MySQLdb\constants
    copying MySQLdb\constants\REFRESH.py -> build\lib.win-amd64-3.5\MySQLdb\constants
    copying MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-3.5\MySQLdb\constants
    running build_ext
    building '_mysql' extension
    error: Unable to find vcvarsall.bat

    ----------------------------------------
Command "c:\python35\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\ghina\\AppData\\Local\\Temp\\pip-build-eo59erqx\\MySQL-python\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\ghina\AppData\Local\Temp\pip-b4pe3d_p-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\ghina\AppData\Local\Temp\pip-build-eo59erqx\MySQL-python\

我在Windows 10上使用python 3.5和django 1.9,我想将django连接到mysql数据库。当我运行django服务器时,我得到:没有名为' MySQLbd'

1 个答案:

答案 0 :(得分:2)

MySQL-Python不支持Python 3.x.根据官方Django documentation,您可以使用以下驱动程序之一:

  

PEP 249中描述了Python数据库API.MySQL有三个实现此API的主要驱动程序:

     

MySQLdb是已开发和支持的本机驱动程序   安迪·杜斯曼十多年来。

     

mysqlclient是MySQLdb的一个分支   特别支持Python 3,可以用作替代品   MySQLdb的。在撰写本文时,这是推荐的选择   使用MySQL与Django。

     

MySQL Connector/Python是纯Python   来自Oracle的驱动程序,不需要MySQL客户端库或   标准库之外的任何Python模块。