[ModuleNotFoundError : No module named 'MySQLdb']

84 Views Asked by At

I'm trying to install the mysqlclient library via pip, but I'm getting this error:

kanishka@kanishka-VivoBook-ASUSLaptop-X512FJ-X512FJ:~/Documents/Ceylone Soft/bcj_dev_back_end$ pip install mysqlclient

Collecting mysqlclient
  Using cached mysqlclient-2.2.4.tar.gz (90 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  ERROR: Command errored out with exit status 1:
   command: '/home/kanishka/Documents/Ceylone Soft/bcj_dev_back_end/BuyChem/bin/python3' /tmp/tmp81chy8bh get_requires_for_build_wheel /tmp/tmpbjs9srac
       cwd: /tmp/pip-install-ulmsnxu3/mysqlclient
  Complete output (24 lines):
  Trying pkg-config --exists mysqlclient
  Command 'pkg-config --exists mysqlclient' returned non-zero exit status 1.
  Trying pkg-config --exists mariadb
  Command 'pkg-config --exists mariadb' returned non-zero exit status 1.
  Trying pkg-config --exists libmariadb
  Command 'pkg-config --exists libmariadb' returned non-zero exit status 1.
  Traceback (most recent call last):
    File "/tmp/tmp81chy8bh", line 280, in <module>
      main()
    File "/tmp/tmp81chy8bh", line 263, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "/tmp/tmp81chy8bh", line 114, in get_requires_for_build_wheel
      return hook(config_settings)
    File "/tmp/pip-build-env-csmolp15/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 325, in get_requires_for_build_wheel
      return self._get_build_requires(config_settings, requirements=['wheel'])
    File "/tmp/pip-build-env-csmolp15/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 295, in _get_build_requires
      self.run_setup()
    File "/tmp/pip-build-env-csmolp15/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 311, in run_setup
      exec(code, locals())
    File "<string>", line 155, in <module>
    File "<string>", line 49, in get_config_posix
    File "<string>", line 28, in find_package_name
  Exception: Can not find valid pkg-config name.
  Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually
  ----------------------------------------
ERROR: Command errored out with exit status 1: '/home/kanishka/Documents/Ceylone Soft/bcj_dev_back_end/BuyChem/bin/python3' /tmp/tmp81chy8bh get_requires_for_build_wheel /tmp/tmpbjs9srac Check the logs for full command output.
1

There are 1 best solutions below

0
user16171413 On

Your error message said you should Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually

mysqlclient uses pkg-config --cflags --ldflags mysqlclient by default for finding compiler/linker flags.

You can use MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS environment variables to customize compiler/linker options.

$ export MYSQLCLIENT_CFLAGS=`pkg-config mysqlclient --cflags`
$ export MYSQLCLIENT_LDFLAGS=`pkg-config mysqlclient --libs`
$ pip install mysqlclient

See https://pypi.org/project/mysqlclient/#description