您当前的位置:首页 > 计算机 > 编程开发 > Python

django安装mysqlclient (Windows下正确安装mysqlclient)

时间:10-24来源:作者:点击数:

由于本人也是初学Python和django。本人使用的Python版本是3.7所以连接MySQL数据库需要安装数据驱动,对应Python3的数据驱动是mysqlclient。因此本人习惯性的使用命令pip install mysqlclient,结果安装失败

(venv) C:\Users\songlihui\PycharmProjects\autotest>pip install mysqlclient
Collecting mysqlclient
  Using cached https://files.pythonhosted.org/packages/ec/fd/83329b9d3e14f7344d1cb31f128e6dbba70c5975c9e57896815dbb1988ad/mysqlclient-1.3.13.tar.gz
Installing collected packages: mysqlclient
  Running setup.py install for mysqlclient ... error
    Complete output from command C:\Users\songlihui\PycharmProjects\autotest\venv\Scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\SONGLI~1\\AppData\\Local\
\Temp\\pip-install-1yliga_x\\mysqlclient\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" i
nstall --record C:\Users\SONGLI~1\AppData\Local\Temp\pip-record-d20e0g2u\install-record.txt --single-version-externally-managed --compile --install-headers C:\Users\songlihui\Pycharm
Projects\autotest\venv\include\site\python3.7\mysqlclient:
    C:\Users\songlihui\AppData\Local\Programs\Python\Python37-32\lib\distutils\dist.py:274: UserWarning: Unknown distribution option: 'long_description_content_type'
      warnings.warn(msg)
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-3.7
    copying _mysql_exceptions.py -> build\lib.win32-3.7
    creating build\lib.win32-3.7\MySQLdb
    copying MySQLdb\__init__.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\compat.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\connections.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\converters.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\cursors.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\release.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\times.py -> build\lib.win32-3.7\MySQLdb
    creating build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\__init__.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\CLIENT.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\CR.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\ER.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\FLAG.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\REFRESH.py -> build\lib.win32-3.7\MySQLdb\constants
    running build_ext
    building '_mysql' extension
    error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

    ----------------------------------------
Command "C:\Users\songlihui\PycharmProjects\autotest\venv\Scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\SONGLI~1\\AppData\\Local\\Temp\\pip-install-1ylig
a_x\\mysqlclient\\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
\SONGLI~1\AppData\Local\Temp\pip-record-d20e0g2u\install-record.txt --single-version-externally-managed --compile --install-headers C:\Users\songlihui\PycharmProjects\autotest\venv\i
nclude\site\python3.7\mysqlclient" failed with error code 1 in C:\Users\SONGLI~1\AppData\Local\Temp\pip-install-1yliga_x\mysqlclient\
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

然后就从网上寻找各种安装的文章,然后发现一篇文章说

到这个地址下载自己版本对应的资源到本地,然后进行安装https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient

然后我进入下载的资源所在目录

然后使用命令安装,结果仍然失败

然后又苦苦的寻找各种解决办法和答案,幸运的是又让我找到一篇文章是这么说的

下载32位的版本安装能成功,因此我有继续下载如下图中的版本

然后继续执行安装的命令,出人意料,竟然成了!至于原因,因为我的Python版本是32。因此分享给大家,大家有问题欢迎留言评论~

方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门