Why mySQLclient is not installed

Question:

I want to install the MySQLclient package on my Cpanel host through the terminal. Because I want to connect my Django project to the database.
When I want to install the necessary packages, everyone installs except MySQLClient.
It also gives an error:

Collecting mysqlclient
  Using cached mysqlclient-2.1.0.tar.gz (87 kB)
  Preparing metadata (setup.py) ... done
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
  ╰─> [43 lines of output]
      mysql_config --version
      /bin/mysql_config: line 8: rpm: command not found
      ['8.0.28']
      mysql_config --libs
      /bin/mysql_config: line 8: rpm: command not found
      ['-L/usr/lib64/mysql', '-lmysqlclient', '-lpthread', '-ldl', '-lssl', '-lcrypto', '-lresolv', '-lm', '-lrt']
      mysql_config --cflags
      /bin/mysql_config: line 8: rpm: command not found
      ['-I/usr/include/mysql', '-m64']
      ext_options:
        library_dirs: ['/usr/lib64/mysql']
        libraries: ['mysqlclient', 'pthread', 'dl', 'resolv', 'm', 'rt']
        extra_compile_args: ['-std=c99', '-m64']
        extra_link_args: []
        include_dirs: ['/usr/include/mysql']
        extra_objects: []
        define_macros: [('version_info', "(2,1,0,'final',0)"), ('__version__', '2.1.0')]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-3.8
      creating build/lib.linux-x86_64-3.8/MySQLdb
      copying MySQLdb/__init__.py -> build/lib.linux-x86_64-3.8/MySQLdb
      copying MySQLdb/_exceptions.py -> build/lib.linux-x86_64-3.8/MySQLdb
      copying MySQLdb/connections.py -> build/lib.linux-x86_64-3.8/MySQLdb
      copying MySQLdb/converters.py -> build/lib.linux-x86_64-3.8/MySQLdb
      copying MySQLdb/cursors.py -> build/lib.linux-x86_64-3.8/MySQLdb
      copying MySQLdb/release.py -> build/lib.linux-x86_64-3.8/MySQLdb
      copying MySQLdb/times.py -> build/lib.linux-x86_64-3.8/MySQLdb
      creating build/lib.linux-x86_64-3.8/MySQLdb/constants
      copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
      copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
      copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
      copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
      copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
      copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
      running build_ext
      building 'MySQLdb._mysql' extension
      creating build/temp.linux-x86_64-3.8
      creating build/temp.linux-x86_64-3.8/MySQLdb
      /opt/rh/devtoolset-7/root/usr/bin/gcc -Wno-unused-result -Wsign-compare -DNDEBUG -D_GNU_SOURCE -fPIC -fwrapv -O2 -fno-semantic-interposition -pthread -Wno-unused-result -Wsign-compare -ffat-lto-objects -flto-partition=none -g -std=c99 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -D_GNU_SOURCE -fPIC -fwrapv -D_GNU_SOURCE -fPIC -fwrapv -O2 -fno-semantic-interposition -pthread -Wno-unused-result -Wsign-compare -ffat-lto-objects -flto-partition=none -g -std=c99 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -D_GNU_SOURCE -fPIC -fwrapv -O2 -fno-semantic-interposition -pthread -Wno-unused-result -Wsign-compare -ffat-lto-objects -flto-partition=none -g -std=c99 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fPIC -Dversion_info=(2,1,0,'final',0) -D__version__=2.1.0 -I/usr/include/mysql -I/home/hrarshai/virtualenv/filmopia_site/3.8/include/python3.8 -c MySQLdb/_mysql.c -o build/temp.linux-x86_64-3.8/MySQLdb/_mysql.o -std=c99 -m64
      error: command '/opt/rh/devtoolset-7/root/usr/bin/gcc' failed: No such file or directory
      [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
  ╰─> [45 lines of output]
      mysql_config --version
      /bin/mysql_config: line 8: rpm: command not found
      ['8.0.28']
      mysql_config --libs
      /bin/mysql_config: line 8: rpm: command not found
      ['-L/usr/lib64/mysql', '-lmysqlclient', '-lpthread', '-ldl', '-lssl', '-lcrypto', '-lresolv', '-lm', '-lrt']
      mysql_config --cflags
      /bin/mysql_config: line 8: rpm: command not found
      ['-I/usr/include/mysql', '-m64']
      ext_options:
        library_dirs: ['/usr/lib64/mysql']
        libraries: ['mysqlclient', 'pthread', 'dl', 'resolv', 'm', 'rt']
        extra_compile_args: ['-std=c99', '-m64']
        extra_link_args: []
        include_dirs: ['/usr/include/mysql']
        extra_objects: []
        define_macros: [('version_info', "(2,1,0,'final',0)"), ('__version__', '2.1.0')]
      running install
      /home/hrarshai/virtualenv/filmopia_site/3.8/lib/python3.8/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
      running build_py
      creating build
      creating build/lib.linux-x86_64-3.8
      creating build/lib.linux-x86_64-3.8/MySQLdb
      copying MySQLdb/__init__.py -> build/lib.linux-x86_64-3.8/MySQLdb
      copying MySQLdb/_exceptions.py -> build/lib.linux-x86_64-3.8/MySQLdb
      copying MySQLdb/connections.py -> build/lib.linux-x86_64-3.8/MySQLdb
      copying MySQLdb/converters.py -> build/lib.linux-x86_64-3.8/MySQLdb
      copying MySQLdb/cursors.py -> build/lib.linux-x86_64-3.8/MySQLdb
      copying MySQLdb/release.py -> build/lib.linux-x86_64-3.8/MySQLdb
      copying MySQLdb/times.py -> build/lib.linux-x86_64-3.8/MySQLdb
      creating build/lib.linux-x86_64-3.8/MySQLdb/constants
      copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
      copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
      copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
      copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
      copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
      copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
      running build_ext
      building 'MySQLdb._mysql' extension
      creating build/temp.linux-x86_64-3.8
      creating build/temp.linux-x86_64-3.8/MySQLdb
      /opt/rh/devtoolset-7/root/usr/bin/gcc -Wno-unused-result -Wsign-compare -DNDEBUG -D_GNU_SOURCE -fPIC -fwrapv -O2 -fno-semantic-interposition -pthread -Wno-unused-result -Wsign-compare -ffat-lto-objects -flto-partition=none -g -std=c99 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -D_GNU_SOURCE -fPIC -fwrapv -D_GNU_SOURCE -fPIC -fwrapv -O2 -fno-semantic-interposition -pthread -Wno-unused-result -Wsign-compare -ffat-lto-objects -flto-partition=none -g -std=c99 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -D_GNU_SOURCE -fPIC -fwrapv -O2 -fno-semantic-interposition -pthread -Wno-unused-result -Wsign-compare -ffat-lto-objects -flto-partition=none -g -std=c99 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fPIC -Dversion_info=(2,1,0,'final',0) -D__version__=2.1.0 -I/usr/include/mysql -I/home/hrarshai/virtualenv/filmopia_site/3.8/include/python3.8 -c MySQLdb/_mysql.c -o build/temp.linux-x86_64-3.8/MySQLdb/_mysql.o -std=c99 -m64
      error: command '/opt/rh/devtoolset-7/root/usr/bin/gcc' failed: No such file or directory
      [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.

I do not understand this error and I do not know what it says.
No matter how much I searched, I did not find anything useful.
Thank you for your help.

Answers:

I found out that the host I was trying to install MySQLclient on had to be configured by the provider for Python 3.9
But because I was in a hurry and could not wait for the host to be configured, I ran the project on Python 3.7 and no problem occurred.

I got the following types of error while installing mysqlclient

  1. error: subprocess-exited-with-error (Running setup.py install for
    mysqlclient did not run successfully)

  2. Python Error: Command ‘X86_64-Linux-Gnu-Gcc’ Failed With Exit Status 1 With Code Examples


Let’s solve this problem using the following commands:

sudo apt-get install gcc python3.x-dev # choose correct python version

sudo apt-get install libxml2-dev libxslt1-dev

This solution worked for me and you can at least try it. I hope it helps.
Thank you!

Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.