Unable to install mysqlclient in django

946 Views Asked by At

I am using the latest python version 3.11 in django framework, for that I need to install mysqlclient . But there was error when I try to install

pip install mysqlclient 

Output like this as error:

Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [23 lines of output]
      
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools
/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for mysqlclient
  Running setup.py clean for mysqlclient
Failed to build mysqlclient
Installing collected packages: mysqlclient
  Running setup.py install for mysqlclient ... error
  error: subprocess-exited-with-error

  × Running setup.py install for mysqlclient did not run successfully.
  │ exit code: 1
  ╰─> [25 lines of output]
      running install
      C:\Users\dsema\PycharmProjects\stock\venv\Lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated.
 Use build and pip and other standards-based tools.
        warnings.warn(
      running build_ext
      building 'MySQLdb._mysql' extension
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools
/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> mysqlclient

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

Any idea can solve it?

1

There are 1 best solutions below

0
On

You're evidently on Windows, so you'd want to make sure pip attempts to use binary packages of mysqlclient rather than even attempting to build one from scratch:

pip install mysqlclient --only-binary=mysqlclient

However, this may install an older version of mysqlclient since there are no binary packages for the 32-bit Python 3.11 you're using. If your machine is capable of running the 64-bit version, I would strongly recommend you switch to it instead, since it's likely 32-bit support will be waning more and more in the near future.