pip install mysqlclient returns "fatal error C1083

2020-01-27 03:29发布

Here is this issue: I attempt to install mysqlclient like so

C:\Users\amccommon349>pip install mysqlclient Collecting mysqlclient Using cached https://files.pythonhosted.org/packages/ec/fd/83329b9d3e14f7344d1 cb31f128e6dbba70c5975c9e57896815dbb1988ad/mysqlclient-1.3.13.tar.gz

Installing collected packages: mysqlclient

Running setup.py install for mysqlclient ... error

Complete output from command c:\users\amccommon349\appdata\local\programs\python\python36\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\AMCCOM~1\\AppData\\Local\\Temp\\pip-install-qcgo48hf\\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\AMCCOM~1\AppData\Local\Temp\pip-record-q4yoftj8\install-record.txt --single-version-externally-managed --compile:

c:\users\amccommon349\appdata\local\programs\python\python36\lib\distutils\d ist.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.win-amd64-3.6
copying _mysql_exceptions.py -> build\lib.win-amd64-3.6
creating build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\__init__.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\compat.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\connections.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\converters.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\cursors.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\release.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\times.py -> build\lib.win-amd64-3.6\MySQLdb
creating build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\__init__.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\CR.py -> build\lib.win-amd64-3.6\MySQLdb\constants

copying MySQLdb\constants\ER.py -> build\lib.win-amd64-3.6\MySQLdb\constants

copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\FLAG.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\REFRESH.py -> build\lib.win-amd64-3.6\MySQLdb\constants

running build_ext

building '_mysql' extension
creating build\temp.win-amd64-3.6
creating build\temp.win-amd64-3.6\Release
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.14.26428\bin\HostX86\x64\cl.exe /c/nologo/Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,3,13,'final',0) -D__version__=1.3.13 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" -Ic:\users\amccommon349\appdata\local\programs\python\python36\include -Ic:\users\amccommon349\appdata\local\programs\python\python36\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.14.26428\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um" "-IC:\ProgramFiles (x86)\Windows Kits\10\include\10.0.17134.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\cppwinrt" /Tc_mysql.c /Fobuild\temp.win-amd64-3.6\Release\_mysql.obj /Zl
_mysql.c
_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\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.14.26428\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2

I made sure I had all of the files needed from visual studios build tools, I downloaded the mysql-python connector, and updated my pip and setup tools. I am a complete beginner to this and would appreciate any input as to how to go about fixing this error.

11条回答
再贱就再见
2楼-- · 2020-01-27 03:40

This is what solved my issue

  • Install MySQL Connector/C (Archived Versions) from here

It is probably installed in the following location C:\Program Files\MySQL\MySQL Connector C 6.1


  • Copy the entire folder MySQL Connector C 6.1 to C:\Program Files (x86)\MySQL\MySQL Connector C 6.1

  • Try executing the command pip3 install mysqlclient.

Successful. Good Job!


Unsuccessful?


  • Install MariaDB connector from here

Probably installed in the location

C:\Program Files\MariaDB\MariaDB Connector C 64-bit

  • Copy the contents from

C:\Program Files\MariaDB\MariaDB Connector C 64-bit\include

and Paste into a folder name it as mariadb and paste it to the location

C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include\


  • Copy the contents from

    C:\Program Files\MariaDB\MariaDB Connector C 64-bit\lib

and Paste into a folder name it as mariadb and paste it to the location

`C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\lib`

  • Try executing the command pip3 install mysqlclient.

This worked for me

查看更多
劫难
3楼-- · 2020-01-27 03:40

I was trying the same for a Django project. I tried using:
pip install mysql-python
which gave me the following error: 'mysql.h': No such file or directory.
After fiddling with reuqirements.txt which gave me yet another error

  Downloading https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip (108kB) 
    Complete output from command python setup.py egg_info: 
    Traceback (most recent call last): 
      File "<string>", line 1, in <module> 
      File "/tmp/pip-install-43_6cfva/MySQL-python/setup.py", line 13, in <module> 
        from setup_posix import get_config 
      File "/tmp/pip-install-43_6cfva/MySQL-python/setup_posix.py", line 2, in <module> 
        from ConfigParser import SafeConfigParser 
    ModuleNotFoundError: No module named 'ConfigParser' 

Finally using this worked for me: pip install mysql-connector
import mysql.connector

查看更多
孤傲高冷的网名
4楼-- · 2020-01-27 03:41

This is a problem with the 64 bit version of python on Windows 10. The following repaired the problem for me.

  1. Install the 32 bit version of python for windows (currently version 3.7.1)
  2. Install visual studio build tools https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2017 for C++
  3. Install the 32 bit mysql connector version 6.1.11 from https://downloads.mysql.com/archives/c-c/

After this I was able to install mysqlclient with pip install mysqlclient.

Hopefully someone will come up with a better solution that doesn't require downgrading to 32 bit because this is not a good solution, it just works. I found a way to work around the mysql issue but ran into the problem again while trying to install channels. It seems python 64 bit is looking for 32 bit libraries instead of 64 bit libraries on windows. So far this solution has solved all of my python build problems on windows.

查看更多
ら.Afraid
5楼-- · 2020-01-27 03:44

None of the solutions above worked for me. Apparently I had to downgrade my Python from 3.7.x to 3.6.4 and that solved the problem for me. Downloadlink for python=3.6.4.

I would recommend to create a new virtual environment for this and not to uninstall your main python. Find extensive documentation on how to create a venv here.

查看更多
我想做一个坏孩纸
6楼-- · 2020-01-27 03:47

I wanted to comment on John's answer but my comment was too long so I had to make another answer. Sorry for that.

John, this helped me a lot, thanks. Not properly reading the logs is a bad habit for many people, myself included.

But instead of downloading the mariadb connector (or searching the net for a prebuilt wheel), I managed to do it with oracle's mysql connector. And I prefer to do symbolic links instead of copying files. Here's what I did using windows 10 x64, python 3.8 x64 and oracle's mysql connector x64:

# run this on an elevated command prompt if your user does not have permission to make symbolic links
# download and install https://downloads.mysql.com/archives/c-c/
mklink /d "C:\Program Files\MySQL\MySQL Connector C 6.1\include\mariadb" "C:\Program Files\MySQL\MySQL Connector C 6.1\include\mysql"
mklink /d "C:\Program Files (x86)\MySQL" "C:\Program Files\MySQL"
mklink /d "C:\Program Files\MySQL\MySQL Connector C 6.1\lib\mariadb" "C:\Program Files\MySQL\MySQL Connector C 6.1\lib\vs14"
mklink "C:\Program Files\MySQL\MySQL Connector C 6.1\lib\vs14\mariadbclient.lib" "C:\Program Files\MySQL\MySQL Connector C 6.1\lib\vs14\mysqlclient.lib"
SET INCLUDE=C:\Program Files\MySQL\MySQL Connector C 6.1\include;%INCLUDE%
python3 -m pip install mysqlclient

And that's it.

查看更多
Root(大扎)
7楼-- · 2020-01-27 03:48

Wasted a lot of time to solve this error i found the solution that worked for me at least.

When i tried to install MYSQL Client

pip install mysqlclient

1st error

MySQLdb/_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory


And also tried to install Django Channels

pip install -U channels

2nd error

error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": https://visualstudio.microsoft.com/downloads/

Download Build tools : Microsoft Build Tools

Stack overflow : How to install/select required Build Tools

Installed build tools. (Happy Coding)


@Ralph Ritoch solution worked for me and as well others those getting Mysql Client error.

But i also installed Django Channels so i followed these steps mentioned below

Follow these steps

  1. Windows 10 64 bit
  2. Python 64 bit 3.7.3
  3. mysql-connector-c-6.1.11-winx64
  4. Build tools

I also installed Django Channels 2.2.0 and not getting any kind of error.

Successfully installed mysqlclient


(Note)

MySQL connector already installed into x86 directory

Copy c:\Program Files\MySQL\MySQL Connector C 6.0.2\ directory to c:\Program Files (x86)\MySQL\MySQL Connector C 6.1\

So i did not changed the directory of MySQL Connector. (You can also check this)

Maybe work for you!

Other Stack solution to change dirctory


Possible Reasons

Why we getting errors.

  1. Python 32/64 bit Version
  2. MySQL Connector 32/64 bit version
  3. Directory issue
  4. Window 32/64 bit version
  5. Build Tools not installed (If getting Microsoft Visual C++ 14.0 is required)

Thanks to all who posted their solution.

查看更多
登录 后发表回答