failed pip install mysqlclient on ubuntu 20.04 with python 3.10
Asked Answered
J

2

6

I am trying to install mysqlclient with pip but it keeps giving me error message, I already have the development from sudo apt-get install python3-dev default-libmysqlclient-dev build-essential, or use this step : LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysqlclient, and this sudo apt-get install libmariadb-dev-compat libmariadb-dev libssl-dev

and in the end i always get this : Building wheel for mysqlclient (setup.py) ... error error: subprocess-exited-with-error, i use python ver 3.10.4 as main, but i have another version (2.7.18, 3.8.10 and 3.9.5),

if i try to download pip install mysqlclient using anaconda, will it cause other problems because i already have python?

this is my whole output

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
  ╰─> [44 lines of output]
      mysql_config --version
      ['10.4.24']
      mysql_config --libs
      ['-L/opt/lampp/lib/', '-lmariadb']
      mysql_config --cflags
      ['-I/opt/lampp/include/mysql', '-I/opt/lampp/include/mysql/mysql']
      ext_options:
        library_dirs: ['/opt/lampp/lib/']
        libraries: ['mariadb']
        extra_compile_args: ['-std=c99']
        extra_link_args: []
        include_dirs: ['/opt/lampp/include/mysql', '/opt/lampp/include/mysql/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-cpython-310
      creating build/lib.linux-x86_64-cpython-310/MySQLdb
      copying MySQLdb/__init__.py -> build/lib.linux-x86_64-cpython-310/MySQLdb
      copying MySQLdb/_exceptions.py -> build/lib.linux-x86_64-cpython-310/MySQLdb
      copying MySQLdb/connections.py -> build/lib.linux-x86_64-cpython-310/MySQLdb
      copying MySQLdb/converters.py -> build/lib.linux-x86_64-cpython-310/MySQLdb
      copying MySQLdb/cursors.py -> build/lib.linux-x86_64-cpython-310/MySQLdb
      copying MySQLdb/release.py -> build/lib.linux-x86_64-cpython-310/MySQLdb
      copying MySQLdb/times.py -> build/lib.linux-x86_64-cpython-310/MySQLdb
      creating build/lib.linux-x86_64-cpython-310/MySQLdb/constants
      copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-cpython-310/MySQLdb/constants
      copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-cpython-310/MySQLdb/constants
      copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-cpython-310/MySQLdb/constants
      copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-cpython-310/MySQLdb/constants
      copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-cpython-310/MySQLdb/constants
      copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-cpython-310/MySQLdb/constants
      running build_ext
      building 'MySQLdb._mysql' extension
      creating build/temp.linux-x86_64-cpython-310
      creating build/temp.linux-x86_64-cpython-310/MySQLdb
      x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Dversion_info=(2,1,0,'final',0) -D__version__=2.1.0 -I/opt/lampp/include/mysql -I/opt/lampp/include/mysql/mysql -I/home/aqila/venv/include -I/usr/include/python3.10 -c MySQLdb/_mysql.c -o build/temp.linux-x86_64-cpython-310/MySQLdb/_mysql.o -std=c99
      MySQLdb/_mysql.c:29:10: fatal error: mysql.h: No such file or directory
         29 | #include "mysql.h"
            |          ^~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
      [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
  ╰─> [46 lines of output]
      mysql_config --version
      ['10.4.24']
      mysql_config --libs
      ['-L/opt/lampp/lib/', '-lmariadb']
      mysql_config --cflags
      ['-I/opt/lampp/include/mysql', '-I/opt/lampp/include/mysql/mysql']
      ext_options:
        library_dirs: ['/opt/lampp/lib/']
        libraries: ['mariadb']
        extra_compile_args: ['-std=c99']
        extra_link_args: []
        include_dirs: ['/opt/lampp/include/mysql', '/opt/lampp/include/mysql/mysql']
        extra_objects: []
        define_macros: [('version_info', "(2,1,0,'final',0)"), ('__version__', '2.1.0')]
      running install
      /home/aqila/venv/lib/python3.10/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-cpython-310
      creating build/lib.linux-x86_64-cpython-310/MySQLdb
      copying MySQLdb/__init__.py -> build/lib.linux-x86_64-cpython-310/MySQLdb
      copying MySQLdb/_exceptions.py -> build/lib.linux-x86_64-cpython-310/MySQLdb
      copying MySQLdb/connections.py -> build/lib.linux-x86_64-cpython-310/MySQLdb
      copying MySQLdb/converters.py -> build/lib.linux-x86_64-cpython-310/MySQLdb
      copying MySQLdb/cursors.py -> build/lib.linux-x86_64-cpython-310/MySQLdb
      copying MySQLdb/release.py -> build/lib.linux-x86_64-cpython-310/MySQLdb
      copying MySQLdb/times.py -> build/lib.linux-x86_64-cpython-310/MySQLdb
      creating build/lib.linux-x86_64-cpython-310/MySQLdb/constants
      copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-cpython-310/MySQLdb/constants
      copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-cpython-310/MySQLdb/constants
      copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-cpython-310/MySQLdb/constants
      copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-cpython-310/MySQLdb/constants
      copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-cpython-310/MySQLdb/constants
      copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-cpython-310/MySQLdb/constants
      running build_ext
      building 'MySQLdb._mysql' extension
      creating build/temp.linux-x86_64-cpython-310
      creating build/temp.linux-x86_64-cpython-310/MySQLdb
      x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Dversion_info=(2,1,0,'final',0) -D__version__=2.1.0 -I/opt/lampp/include/mysql -I/opt/lampp/include/mysql/mysql -I/home/aqila/venv/include -I/usr/include/python3.10 -c MySQLdb/_mysql.c -o build/temp.linux-x86_64-cpython-310/MySQLdb/_mysql.o -std=c99
      MySQLdb/_mysql.c:29:10: fatal error: mysql.h: No such file or directory
         29 | #include "mysql.h"
            |          ^~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
      [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.```
Jestude answered 12/5, 2022 at 3:36 Comment(2)
Please try to use virtuenv to create a python 3.10 environment and then try installing the required mysql package, it seems that pip from python2 might be getting used instead of pip from python3Caseose
@Caseose i've activated my venv before, and it's from my pip: pip 22.0.4 from /home/aqila/.local/lib/python3.10/site-packages/pip (python 3.10), I tried to install it using 2 different envsJestude
S
10

I've just encountered the same problem, getting error messages when installing mysqlclient using pip. After some searches, I found this blog post. Following the blog post, we need to install several libraries:

sudo apt-get install python3.10-dev
sudo apt-get install mysql-client
sudo apt-get install libmysqlclient-dev
sudo apt-get install libssl-dev

After successfully install the above libraries, then we can install mysqlclient like this:

pip install mysqlclient

It works for me.

Seventh answered 20/10, 2022 at 23:11 Comment(1)
sudo apt-get install python3.8-dev or whatever python you use for other versionsPitman
B
5

This is how I did it in 2023:

From the mysqlclient repo they mentioned to install these dependencies

sudo apt-get install python3-dev default-libmysqlclient-dev build-essential pkg-config

I think the pkg-config is important here.

Burlingame answered 19/8, 2023 at 13:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.