文章目录
python版本和MySQLdb
关于MySQLdb,首先要明确的是:
- python2才有MySQLdb
- python3是pymysql或者mysqlclient
pycharm(Windows)的默认python版本
如上所述,想要使用MySQLdb,python版本需要为python2,所以pycharm,也就是Windows的默认python版本要为python2,即在“terminal”命令行下输入“python”,进入的是python2。
如果进入的是python3的话,需要安装python2环境,然后再将python2的环境变量加在python3前面。
确保环境为python2后,再开始下面的安装。
可能的错误
3.1 Could not find a version that satisfies the requirement mysqldb (from versions
在pycharm的“Terminal”输入 pip install mysqldb
进行安装时,开始报如下错误:
Could not find a version that satisfies the requirement mysqldb (from versions
: )
No matching distribution found for mysqldb
查资料后说要先安装 MySQL-python,所以输入 pip install MySQL-python
安装。
3.2 Unable to find vcvarsall.bat
又报如下错误:
error: Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat).
Get it from http://aka.ms/vcpython27
缺少vc的一个库,我们根据提示到 http://aka.ms/vcpython27 这里,也就是下面的地址,下载一下
https://www.microsoft.com/en-us/download/confirmation.aspx?id=44266
安装好后,再次执行命令 :pip install mysql-python。
3.3 C++ for Python\9.0\VC\Bin\amd64\cl.exe"’ failed with exit status 2
还是报错:
No such file or directory
error: command '"C:\Users\...\Microsoft\Visua
l C++ for Python\9.0\VC\Bin\amd64\cl.exe"' failed with exit status 2
这是因为缺少驱动。
MySQL-python-1.2.3.win-amd64-py2.7.exe
可以到下面的地址下载(亲测有效)
http://sourceforge.net/projects/mysqlpythonwinx64py272/files/MySQL-python-1.2.3.win-amd64-py2.7_2.exe/download
安装好后,再执行pip install MySQL-python
和pip install mysqldb
,之后就没有报错,MySQLdb也可以用了~
参考:
https://www.jianshu.com/p/74943db07cf1