[Python] installing mysqlclient with pip fails "subprocess-exited-with-error"

Discussão em 'Python' iniciado por Stack, Dezembro 16, 2024.

  1. Stack

    Stack Membro Participativo

    I'm using Linux Mint 22 and encountering an issue when trying to install mysqlclient with pip. The installation fails and returns the error "subprocess-exited-with-error' Below is the console output:

    (env) sh-5.2$ pip install mysqlclient
    Collecting mysqlclient
    Using cached mysqlclient-2.2.6.tar.gz (91 kB)
    Installing build dependencies ... done
    Getting requirements to build wheel ... error
    error: subprocess-exited-with-error

    × Getting requirements to build wheel did not run successfully.
    │ exit code: 1
    ╰─> [29 lines of output]
    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.
    Trying pkg-config --exists perconaserverclient
    Command 'pkg-config --exists perconaserverclient' returned non-zero exit status 1.
    Traceback (most recent call last):
    File "/home/usr/School/24-25/P2/project en samenwerken/Project/env/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
    main()
    File "/home/usr/School/24-25/P2/project en samenwerken/Project/env/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
    json_out['return_val'] = hook(**hook_input['kwargs'])
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/usr/School/24-25/P2/project en samenwerken/Project/env/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
    return hook(config_settings)
    ^^^^^^^^^^^^^^^^^^^^^
    File "/tmp/pip-build-env-2g4_q5k5/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 334, in get_requires_for_build_wheel
    return self._get_build_requires(config_settings, requirements=[])
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/tmp/pip-build-env-2g4_q5k5/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 304, in _get_build_requires
    self.run_setup()
    File "/tmp/pip-build-env-2g4_q5k5/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 320, 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
    [end of output]

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

    × Getting requirements to build wheel did not run successfully.
    │ exit code: 1
    ╰─> See above for output.

    note: This error originates from a subprocess, and is likely not a problem with pip.
    (env) sh-5.2$


    I followed advice from other posts and installed the necessary dependencies using the following command:

    usr@usr-laptop:~$ sudo apt-get install python3-dev default-libmysqlclient-dev build-essential pkg-config mysql-server libffi-dev libssl-dev libmysqlclient-dev


    output confirms that all packages are already installed:

    Reading package lists... Done
    Building dependency tree... Done
    Reading state information... Done
    python3-dev is already the newest version (3.12.3-0ubuntu2).
    default-libmysqlclient-dev is already the newest version (1.1.0build1).
    build-essential is already the newest version (12.10ubuntu1).
    pkg-config is already the newest version (1.8.1-2build1).
    mysql-server is already the newest version (8.0.40-0ubuntu0.24.04.1).
    libffi-dev is already the newest version (3.4.6-1build1).
    libssl-dev is already the newest version (3.0.13-0ubuntu3.4).
    libmysqlclient-dev is already the newest version (8.0.40-0ubuntu0.24.04.1).
    0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.


    Even after installing all dependencies the install still fails. The issue isn't with pip, i can install other packages just fine.

    The solution in Mysqlclient cannot install via pip, cannot find pkg-config name in Ubuntu doesn't work for me. The solution in that question doesn't solve it since i have already installed the packages

    pkg-config python3-dev default-libmysqlclient-dev build-essential


    Trying to install with custom flags fails too.

    usr@usr-laptop:~$ sudo find /usr/include -name "mysql.h"
    /usr/include/mysql/mysql.h
    usr@usr-laptop:~$ sudo find /usr/lib -name "libmysqlclient.so*"
    /usr/lib/x86_64-linux-gnu/libmysqlclient.so
    /usr/lib/x86_64-linux-gnu/libmysqlclient.so.21.2.40
    /usr/lib/x86_64-linux-gnu/libmysqlclient.so.21
    usr@usr-laptop:~$


    (env) sh-5.2$ MYSQLCLIENT_CFLAGS="-I/usr/include/mysql" MYSQLCLIENT_LDFLAGS="-L/usr/lib/x86_64-linux-gnu -lmysqlclient" pip3 install mysqlc
    lient


    Output:

    Collecting mysqlclient
    Using cached mysqlclient-2.2.6.tar.gz (91 kB)
    Installing build dependencies ... done
    Getting requirements to build wheel ... done
    Preparing metadata (pyproject.toml) ... done
    Building wheels for collected packages: mysqlclient
    Building wheel for mysqlclient (pyproject.toml) ... error
    error: subprocess-exited-with-error

    × Building wheel for mysqlclient (pyproject.toml) did not run successfully.
    │ exit code: 1
    ╰─> [40 lines of output]
    # Options for building extension module:
    extra_compile_args: ['-I/usr/include/mysql', '-std=c99']
    extra_link_args: ['-L/usr/lib/x86_64-linux-gnu', '-lmysqlclient']
    define_macros: [('version_info', (2, 2, 6, 'final', 0)), ('__version__', '2.2.6')]
    running bdist_wheel
    running build
    running build_py
    creating build/lib.linux-x86_64-cpython-312/MySQLdb
    copying src/MySQLdb/__init__.py -> build/lib.linux-x86_64-cpython-312/MySQLdb
    copying src/MySQLdb/_exceptions.py -> build/lib.linux-x86_64-cpython-312/MySQLdb
    copying src/MySQLdb/connections.py -> build/lib.linux-x86_64-cpython-312/MySQLdb
    copying src/MySQLdb/converters.py -> build/lib.linux-x86_64-cpython-312/MySQLdb
    copying src/MySQLdb/cursors.py -> build/lib.linux-x86_64-cpython-312/MySQLdb
    copying src/MySQLdb/release.py -> build/lib.linux-x86_64-cpython-312/MySQLdb
    copying src/MySQLdb/times.py -> build/lib.linux-x86_64-cpython-312/MySQLdb
    creating build/lib.linux-x86_64-cpython-312/MySQLdb/constants
    copying src/MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-cpython-312/MySQLdb/constants
    copying src/MySQLdb/constants/CR.py -> build/lib.linux-x86_64-cpython-312/MySQLdb/constants
    copying src/MySQLdb/constants/ER.py -> build/lib.linux-x86_64-cpython-312/MySQLdb/constants
    copying src/MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-cpython-312/MySQLdb/constants
    copying src/MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-cpython-312/MySQLdb/constants
    copying src/MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-cpython-312/MySQLdb/constants
    running egg_info
    writing src/mysqlclient.egg-info/PKG-INFO
    writing dependency_links to src/mysqlclient.egg-info/dependency_links.txt
    writing top-level names to src/mysqlclient.egg-info/top_level.txt
    reading manifest file 'src/mysqlclient.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    adding license file 'LICENSE'
    writing manifest file 'src/mysqlclient.egg-info/SOURCES.txt'
    copying src/MySQLdb/_mysql.c -> build/lib.linux-x86_64-cpython-312/MySQLdb
    running build_ext
    building 'MySQLdb._mysql' extension
    creating build/temp.linux-x86_64-cpython-312/src/MySQLdb
    x86_64-unknown-linux-gnu-gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O3 -Wall -O2 -pipe -g -Wp,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -O3 -O2 -pipe -g -Wp,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -O3 -fPIC "-Dversion_info=(2, 2, 6, 'final', 0)" -D__version__=2.2.6 "-I/home/usr/School/24-25/P2/project en samenwerken/Project/env/include" -I/usr/include/python3.12 -I/usr/include/x86_64-linux-gnu/python3.12 -c src/MySQLdb/_mysql.c -o build/temp.linux-x86_64-cpython-312/src/MySQLdb/_mysql.o -I/usr/include/mysql -std=c99
    src/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-unknown-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
    Failed to build mysqlclient
    ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (mysqlclient)
    (env) sh-5.2$

    Continue reading...

Compartilhe esta Página