Pip install mysqlclient returns "fatal error C1083: Cannot open file: 'mysql.h': No such file or directory"
Fix the fatal error C1083: Cannot open file: 'mysql.h': No such file or directory
when installing mysqlclient
. Carry out the MySQL Connector C installation, then configure the environment variables correctly:
Update C:\Path_to_MySQL_Connector
to match your installation path. Proceed to run these commands before trying the installation again.
Pre-checks: saving future headaches
Before launching your install mysqlclient endeavor, ensure that:
- Python setup is 64-bit, especially crucial when using MySQL 64-bit.
- Your chosen mysqlclient version gels with your MySQL and Python versions.
- The MySQL-python connector has been correctly installed, providing the groundwork for Python to interact with MySQL.
If the typical pip install
shudders, Unofficial Windows Binaries for Python provides a handy lifeline.
Smoothing the installation process with .whl files
A .whl file is a pre-built package, which you can install, sparing the compiling process. To make use of this time-saver:
- Pluck a .whl file that’s compatible with your system and Python version from Unofficial Windows Binaries for Python.
- Let pip handle the rest
pip install [filename].whl
. This route bypasses the need for Visual Studio build tools.
Dealing with technical discrepancies
The MariaDB C/C++ connector is a valuable backup, especially if the infamous mysql.h
file still remains hidden after installing MySQL Connector C. Here’s your game plan:
- Set up the MariaDB C/C++ connector.
- Relocate the contents from the
include
andlib
folders of the MariaDB packet right into your MySQL Connector C directories. - Give
pip install mysqlclient
another shot.
Clearing the path to success
Sometimes, the installer might look for MySQL Connector/C in a particular nook, say Program Files
. Go ahead and move the MySQL Connector C 6.1 folder to Program Files (x86)/MySQL
or the Program Files
folder, whichever suits your system.
Ensure you create any required folders that may not have automatically sprouted during your MySQL installation.
What if things still don't go as planned?
Everyone encounters a roadblock. Here's how to circumvent them:
- Inspect the
mysql.h
file's presence in the MySQL Connector/C installation directory. - If relocating didn't solve it, reinstall Python, ensuring it's the 64-bit version in harmony with your MySQL installation.
- Encountering compatibility issues? Attempt reinstalling the mysqlclient after revamping the Python or MySQL versions.
Preparing for success
Sprinkle these in your strategy to ensure a smooth installation:
- Unofficial Windows Binaries: Pluck the
mysqlclient
.whl file. - Check Compatibility: Match your Python and MySQL versions with the .whl file.
- Simplify: Bypass the need for Visual Studio build tools using precompiled wheels.
Was this article helpful?