在PyCharm中使用MySQL

import pymysql

pymysql.install_as_MySQLdb()

执行python manage.py makemigrations时报错:

mysqlclient 1.3.13 or newer is required; you have 0.9.3.

于是放弃使用pymysql这个包,直接用mysqlclient算了,那么安装mysqlclient 。

使用命令:pip install mysqlclient 安装,但是又出错:

    MySQLdb/_mysql.c(29): fatal error C1083: 无法打开包括文件: “mysql.h”: No such file or directory

    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\……\\x64\\cl.exe'

查看MySQL安装目录的文件include中是有mysql.h这个文件的,另外关Visual Studio什么事呢?好菜哦,想不明白,再百一百

,有人说去https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient下载安装包,然后我下载了1.3.13的64位那个文件,放到项目文件夹后,信心满满的执行安装命令:

pip install mysqlclient-1.3.13-cp34-cp34m-win32.whl。

 

结果又败了:

mysqlclient-1.3.13-cp34-cp34m-win_amd64.whl is not a supported wheel on this platform.

再百一百,说是换成32位的,结果还是败了:

mysqlclient-1.3.13-cp34-cp34m-win32.whl is not a supported wheel on this platform.

谁叫是菜鸟呢,继续百一百吧,说是先看一下pip支持的文件格式

>>> import pip

>>> print(pip.pep425tags.get_supported()) # 列出pip支持的文件名格式

[('cp27', 'none', 'win32'), ('py2', 'none', 'win32'), ('cp27', 'none', 'any'), ('cp2', 'none', 'any'), ('cp26', 'none', 'any'), ('cp25', 'none', 'any'), ('cp24', 'none', 'any'), ('cp23', 'none', 'any'), ('cp22', 'none', 'any'), ('cp21', 'none', 'any'), ('cp20', 'none', 'any'), ('py27', 'none', 'any'), ('py2', 'none', 'any'), ('py26', 'none', 'any'), ('py25', 'none', 'any'), ('py24', 'none', 'any'), ('py23', 'none', 'any'), ('py22', 'none', 'any'), ('py21', 'none', 'any'), ('py20', 'none', 'any')]

 

于是更改mysqlclient-1.3.13-cp36-cp36m-win_amd64.whl文件名再进行安装

最终更改为mysqlclient-1.3.13-py36-none-any.whl之后:

Processing d:\rd\py\myoa\mysqlclient-1.3.13-py36-none-any.whl

Installing collected packages: mysqlclient

Successfully installed mysqlclient-1.3.13

终于安装完成。

好了,安装完成,总是满怀希望的,继续debug吧,然后

ImportError: DLL load failed while importing _mysql: 找不到指定的模块。

为什么?百了一下,这是PyCharm自带的Python版本问题,创建应用时他会在当前应用中生成自己的一个,把他换掉就可以了

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章