I installed Python 2.7.15rci and Python 3.6.7 on Ubuntu. When i did ‘pip list’ on virtualenv it returns me:
Django (2.1.5)
pip (9.0.1)
pkg-resources (0.0.0)
pytz (2018.9)
setuptools (39.0.1)
wheel (0.32.3)
I’m trying to install mysqlclient (pip install mysqlclient) and returns an error.
unable to execute 'x86_64-linux-gnu-gcc': No such file or directory
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
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
Complete output from command /home/david/env/project/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-pq18uxjj/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-y28h4ou0-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/david/env/project/include/site/python3.6/mysqlclient:
/usr/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type'
warnings.warn(msg)
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.6
creating build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/__init__.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/_exceptions.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/compat.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/connections.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/converters.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/cursors.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/release.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/times.py -> build/lib.linux-x86_64-3.6/MySQLdb
creating build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
running build_ext
building 'MySQLdb._mysql' extension
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/MySQLdb
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Dversion_info=(1,4,1,'final',0) -D__version__=1.4.1 -I/usr/include/mysql -I/home/david/env/project/include -I/usr/include/python3.6m -c MySQLdb/_mysql.c -o build/temp.linux-x86_64-3.6/MySQLdb/_mysql.o
unable to execute 'x86_64-linux-gnu-gcc': No such file or directory
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
Command "/home/david/env/project/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-pq18uxjj/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-y28h4ou0-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/david/env/project/include/site/python3.6/mysqlclient" failed with error code 1 in /tmp/pip-build-pq18uxjj/mysqlclient/
So, I have tried different methods found like:
sudo apt-get install python-dev
sudo apt-get install python3-dev
sudo apt-get install libmysqlclient-dev
and some more… but none of them work for me and the problem persists.
Any suggestions?
Thank you!
I want to install MySQL on my Ubuntu 20.10 desktop, but I’m facing issues.
I tried installing python3-dev
and libmysqlclient-dev
.
When running:
pip3 install mysqlclient
I keep getting the error below:
How may I solve this?
asked Mar 4, 2021 at 18:33
1
Check this thread, maybe it helps you.
Error installing libmysqlclient-dev on Ubuntu 20.04
Step 0: sudo apt install python3-dev build-essential
Step 1: sudo apt install libssl1.1
Step 2: sudo apt install libssl1.1=1.1.1f-1ubuntu2
Step 3: sudo apt install libssl-dev
Step 4: sudo apt install libmysqlclient-dev
Step 5: pip3 install mysqlclient
That’s it!
ps: To find out these all steps, I was spent almost 4-5 Hours.
answered Apr 16, 2021 at 19:35
1
As mentioned here you should do:
sudo apt-get install python3-dev default-libmysqlclient-dev build-essential
Debian / Ubuntusudo yum install python3-devel mysql-devel
Red Hat / CentOS
After that just do pip install mysqlclient
answered Aug 5, 2021 at 11:40
2
This can usually be resolved with the libffi-dev
libraries; libffi.so
specifically. It can be installed via apt
with:
sudo apt install libffi-dev
Note: I have not found a way to install this via pip3
. Do let me know if you find it somewhere.
Once libffi-dev
is installed, run ldconfig
to load the new .so
.
Important: If you compiled your own Python installation, then you will need to recompile it for libffi-dev
to be loaded.
answered Mar 4, 2021 at 23:59
If you are having trouble while setting up virtual environment then do mention python version:
sudo apt-get install python3.5-dev
sudo apt-get install mysql-client
sudo apt-get install libmysqlclient-dev
sudo apt-get install libssl-dev
answered Aug 11, 2021 at 11:15
Exception: Can not find valid pkg-config name. Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually
If you encounter something like above message in between too then, below command will do the thing which is setting above os environment variables.
sudo apt-get install python3-dev default-libmysqlclient-dev build-essential pkg-config
pip install mysqlclient
References — https://github.com/PyMySQL/mysqlclient#readme
answered Aug 13 at 14:49
You must log in to answer this question.
Not the answer you’re looking for? Browse other questions tagged
.
Not the answer you’re looking for? Browse other questions tagged
.
The error «pip install mysqlclient» is a common issue encountered by users when trying to install the mysqlclient library for Python using pip. The error is often caused by missing dependencies or conflicting versions of libraries. In this guide, we’ll take a look at several methods to resolve this error and successfully install the mysqlclient library.
Method 1: Installing Dependencies
To fix the «pip install mysqlclient error» in Python, you can try installing the dependencies required by mysqlclient. Here are the steps to do it:
- Install the build-essential package and the Python development headers:
sudo apt-get install build-essential python-dev
- Install the MySQL client library:
sudo apt-get install libmysqlclient-dev
- Install mysqlclient using pip:
Here is what the code looks like in the terminal:
$ sudo apt-get install build-essential python-dev
$ sudo apt-get install libmysqlclient-dev
$ pip install mysqlclient
By following these steps, you should be able to install mysqlclient without any errors.
To fix the «pip install mysqlclient error» in Python, updating setuptools is one of the solutions. Here are the steps to update setuptools:
Step 1: Open your command prompt or terminal.
Step 2: Run the following command to install the latest version of setuptools:
pip install --upgrade setuptools
Step 3: After the installation is complete, try to install mysqlclient again using the following command:
If the above steps do not work, you can try uninstalling and reinstalling mysqlclient using the following commands:
pip uninstall mysqlclient
pip install mysqlclient
If you still encounter errors, you can try installing the dependencies required for mysqlclient using the following commands:
sudo apt-get install python-dev default-libmysqlclient-dev build-essential
Once the dependencies are installed, try to install mysqlclient again using the following command:
That’s it! Updating setuptools and installing the required dependencies should fix the «pip install mysqlclient error» in Python.
Method 3: Installing a Specific Version of mysqlclient
To fix the «pip install mysqlclient error» in Python, you can try installing a specific version of mysqlclient. Here are the steps:
- First, uninstall any existing mysqlclient packages by running the following command in your terminal:
pip uninstall mysqlclient
-
Next, find the version of mysqlclient that works with your Python version and operating system. You can do this by visiting the PyPI page for mysqlclient (https://pypi.org/project/mysqlclient/) and looking at the «Download files» section. Find the version that matches your Python version and operating system, and make a note of the version number.
-
Install the specific version of mysqlclient using pip. Replace
<version>
with the version number you found in step 2:
pip install mysqlclient==<version>
- Test that mysqlclient is installed correctly by running the following Python code:
import MySQLdb
db = MySQLdb.connect(host="localhost", user="username", passwd="password", db="database")
cursor = db.cursor()
cursor.execute("SELECT VERSION()")
data = cursor.fetchone()
print("Database version : %s " % data)
db.close()
If you see the version of your MySQL database printed to the console, then mysqlclient is installed correctly.
Note: If you encounter any errors during the installation process, make sure that you have the necessary dependencies installed on your system. For example, on Ubuntu you may need to run sudo apt-get install libmysqlclient-dev
before installing mysqlclient.
Method 4: Installing mysqlclient via Wheel File
If you are facing an error while installing mysqlclient via pip, you can try installing it via a Wheel File. Here’s how to do it:
Step 1: Download the Wheel File
First, you need to download the Wheel File for mysqlclient. You can download it from this link. Make sure to download the appropriate version of the Wheel File based on your Python version and system architecture.
Step 2: Install the Wheel File
Once you have downloaded the Wheel File, you can install it using pip. Open your terminal or command prompt and navigate to the directory where the Wheel File is located. Then, run the following command:
pip install <path_to_wheel_file>
Replace <path_to_wheel_file>
with the actual path to the Wheel File you downloaded.
Step 3: Verify the Installation
After the installation is complete, you can verify it by importing mysqlclient in your Python code. Open a Python shell or create a new Python file and add the following code:
If there are no errors, it means that mysqlclient has been installed successfully.
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.```
Describe the bug
When try into virtualenv but also in global environments -> pip install mysqlclient
failed to install with the follow stacktrace:
Collecting mysqlclient
Using cached mysqlclient-2.1.1.tar.gz (88 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
['8.0.33']
mysql_config --libs
['-L/opt/homebrew/opt/mysql-client/lib', '-lmysqlclient', '-lzlib', '-lzstd', '-L/opt/homebrew/opt/openssl@1.1/lib', '-lssl', '-lcrypto', '-lresolv']
mysql_config --cflags
['-I/opt/homebrew/opt/mysql-client/include/mysql']
ext_options:
library_dirs: ['/opt/homebrew/opt/mysql-client/lib', '/opt/homebrew/opt/openssl@1.1/lib']
libraries: ['mysqlclient', 'zlib', 'resolv']
extra_compile_args: ['-std=c99']
extra_link_args: []
include_dirs: ['/opt/homebrew/opt/mysql-client/include/mysql']
extra_objects: []
define_macros: [('version_info', "(2,1,1,'final',0)"), ('__version__', '2.1.1')]
running bdist_wheel
running build
running build_py
creating build
creating build/lib.macosx-10.9-universal2-3.9
creating build/lib.macosx-10.9-universal2-3.9/MySQLdb
copying MySQLdb/__init__.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb
copying MySQLdb/_exceptions.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb
copying MySQLdb/connections.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb
copying MySQLdb/converters.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb
copying MySQLdb/cursors.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb
copying MySQLdb/release.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb
copying MySQLdb/times.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb
creating build/lib.macosx-10.9-universal2-3.9/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb/constants
running build_ext
building 'MySQLdb._mysql' extension
creating build/temp.macosx-10.9-universal2-3.9
creating build/temp.macosx-10.9-universal2-3.9/MySQLdb
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Headers -arch arm64 -arch x86_64 -Werror=implicit-function-declaration -Dversion_info=(2,1,1,'final',0) -D__version__=2.1.1 -I/opt/homebrew/opt/mysql-client/include/mysql -I/Users/hrcoffee6/my_venv/django_3/include -I/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/include/python3.9 -c MySQLdb/_mysql.c -o build/temp.macosx-10.9-universal2-3.9/MySQLdb/_mysql.o -std=c99
clang -bundle -undefined dynamic_lookup -arch arm64 -arch x86_64 -Wl,-headerpad,0x1000 build/temp.macosx-10.9-universal2-3.9/MySQLdb/_mysql.o -L/opt/homebrew/opt/mysql-client/lib -L/opt/homebrew/opt/openssl@1.1/lib -lmysqlclient -lzlib -lresolv -o build/lib.macosx-10.9-universal2-3.9/MySQLdb/_mysql.cpython-39-darwin.so
ld: library not found for -lzlib
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command '/usr/bin/clang' 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
ERROR: Could not build wheels for mysqlclient, which is required to install pyproject.toml-based projects
Environment
Macbook Pro M2
Python 3.9.6
MySQL Server
- 8.0.33 (Homebrew)
MySQL Client
- OS (MacOS Ventura 13.3.1 (a)):
Additional context
brew install mysqlclient -> installed successfully
https://stackoverflow.com/questions/76177559/library-not-found-for-lzlib-mac-m2-chip-pip-install-mysqlclient