无法打开包含文件:'mysql.h':没有这样的文件或目录

时间:2019-11-12 07:38:51

标签: python mysql django

我正在尝试安装Django项目的requirements.txt,它给了我以下错误:

  

MySQLdb / _mysql.c(29):致命错误C1083:无法打开包含文件:   'mysql.h':没有这样的文件或目录

我尝试了以下命令,但它们似乎对我不起作用

我尝试过的命令:

   pip install mysqlclient==1.3.4

   pip install --only-binary :all: mysqlclient

错误:

Installing collected packages: mysqlclient, wheel, gunicorn, psycopg2, python-dateutil, numpy, pandas, django-pandas, kuchbhi, pyparsing, pulp, sqlalchemy, xlwt, django-bootstrap-modal-forms, MarkupSafe, jinja2, branca, certifi, urllib3, chardet, idna, requests, folium, django-widget-tweaks, googlemaps, decorator, ipython-genutils, traitlets, pywin32, jupyter-core, pyrsistent, attrs, more-itertools, zipp, importlib-metadata, jsonschema, nbformat, pyzmq, tornado, jupyter-client, pickleshare, backcall, parso, jedi, wcwidth, prompt-toolkit, colorama, pygments, ipython, ipykernel, testpath, defusedxml, pandocfilters, webencodings, bleach, mistune, entrypoints, nbconvert, pywinpty, terminado, Send2Trash, prometheus-client, notebook, widgetsnbextension, ipywidgets, geojson, gmaps, django-fullcalendar, geographiclib, geopy, pillow, brotli, django-brotli, zopfli, django-static-compress, django-clear-cache, pyjwt, djangorestframework, djangorestframework-simplejwt, djangorestframework-jwt, django-cors-headers
  Found existing installation: mysqlclient 1.3.12
    Uninstalling mysqlclient-1.3.12:
      Successfully uninstalled mysqlclient-1.3.12
  Running setup.py install for mysqlclient ... error
    Complete output from command c:\users\rahul\appdata\local\programs\python\python36-32\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Rahul\\AppData\\Local\\Temp\\pip-build-pul5j4z0\\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\Rahul\AppData\Local\Temp\pip-mn6g7opp-record\install-record.txt --single-version-externally-managed --compile:
    c:\users\rahul\appdata\local\programs\python\python36-32\lib\distutils\dist.py:261: 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.6
    creating build\lib.win32-3.6\MySQLdb
    copying MySQLdb\__init__.py -> build\lib.win32-3.6\MySQLdb
    copying MySQLdb\_exceptions.py -> build\lib.win32-3.6\MySQLdb
    copying MySQLdb\compat.py -> build\lib.win32-3.6\MySQLdb
    copying MySQLdb\connections.py -> build\lib.win32-3.6\MySQLdb
    copying MySQLdb\converters.py -> build\lib.win32-3.6\MySQLdb
    copying MySQLdb\cursors.py -> build\lib.win32-3.6\MySQLdb
    copying MySQLdb\release.py -> build\lib.win32-3.6\MySQLdb
    copying MySQLdb\times.py -> build\lib.win32-3.6\MySQLdb
    creating build\lib.win32-3.6\MySQLdb\constants
    copying MySQLdb\constants\__init__.py -> build\lib.win32-3.6\MySQLdb\constants
    copying MySQLdb\constants\CLIENT.py -> build\lib.win32-3.6\MySQLdb\constants
    copying MySQLdb\constants\CR.py -> build\lib.win32-3.6\MySQLdb\constants
    copying MySQLdb\constants\ER.py -> build\lib.win32-3.6\MySQLdb\constants
    copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-3.6\MySQLdb\constants
    copying MySQLdb\constants\FLAG.py -> build\lib.win32-3.6\MySQLdb\constants
    running build_ext
    building 'MySQLdb._mysql' extension
    creating build\temp.win32-3.6
    creating build\temp.win32-3.6\Release
    creating build\temp.win32-3.6\Release\MySQLdb
    C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MT -Dversion_info=(1,4,1,'final',0) -D__version__=1.4.1 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include\mariadb" -Ic:\users\rahul\appdata\local\programs\python\python36-32\include -Ic:\users\rahul\appdata\local\programs\python\python36-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt" /TcMySQLdb/_mysql.c /Fobuild\temp.win32-3.6\Release\MySQLdb/_mysql.obj /Zl /D_CRT_SECURE_NO_WARNINGS
    _mysql.c
    MySQLdb/_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.23.28105\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2

    ----------------------------------------
  Rolling back uninstall of mysqlclient
Command "c:\users\rahul\appdata\local\programs\python\python36-32\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Rahul\\AppData\\Local\\Temp\\pip-build-pul5j4z0\\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\Rahul\AppData\Local\Temp\pip-mn6g7opp-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Rahul\AppData\Local\Temp\pip-build-pul5j4z0\mysqlclient\

1 个答案:

答案 0 :(得分:2)

问题是您使用的是32位版本的Python 3.6,对于该版本的mysqlclient,没有轮子(二进制版本)。

您会看到here in the package file list上有 用于Windows 1.3.12的Windows x32滚轮–试试吧。

pip install mysqlclient==1.3.12

如果无法安装正确的车轮,请从上述清单中下载mysqlclient-1.3.12-cp36-cp36m-win32.whl,然后使用pip install ./mysqlclient-1.3.12-cp36-cp36m-win32.whl

进行安装。

如果可以的话,最好还是切换到x64版本的Python。