Trusted answers to developer questions
Trusted Answers to Developer Questions
Related Tags
python
django
communitycreator
NDUKWE CHIDERA K.
To successfully use Python to communicate to any database, you need to have the Python database client for that database.
When you develop Django web applications and start a project successfully, the project is shipped with the sqlite
database and its settings for your use. If you want to use a different database, such as MySql
, you have to make changes in the settings file and make sure you install the database client for that database.
Note: You can follow this link to learn how to successfully start a Django project.
What is mysqlclient
?
This is a database client application that serves as the medium/interface between the userthe client running Python codes and the mysql
database. mysqlclient
was developed to replace MySql-python and provides support for Python3, although it is backward compatible as well.
How to use mySqlclient
To use this service, you have to install it through the Python package installer pip
, as shown below:
pip install mysqlclient
This command will automatically download and install the mysqlclient
package into your device. However, this process is not always problem-free due to some reasons, like pip
trying to install the latest version that might not match properly with your system.
If a problem arises, pip
will throw an error with a message like mysqliclient installation error
.
How to fix this problem
- First, check that you are connected to the internet and it is stable. Try to run the command again.
- Next, you will have to manually download and install the package if the problem persists. To do this, you can Google the binary file of
mysqlclient
that is compatible with your device, or you can go to this site. Please note that this website is not officially owned by the owners ofmysql
and is more like a support/community forum. - Now, after a successful download, you can move the package to the parent directory where your Django project is located, or you can place it anywhere you wish. Go to your command prompt or terminal and use the command below:
cd/to/my/directory/path/to_mysqlclient.exe/file pip install mysqlclient
If I place the package in my Django app parent directory, my command will look something like this:
C:Usersmydevicecodesdjangoapps pip install mysqlclient‑1.4.6‑cp39‑cp39‑win32.whl
You don’t need to type the whole name when you enter the directory that contains the file. Just enter the first few letters of the file’s name and hit the
tab
key to complete the name.
After that, hit enter
to install the package. mysqlclient
should install successfully now.
RELATED TAGS
python
django
communitycreator
CONTRIBUTOR
NDUKWE CHIDERA K.
Learn in-demand tech skills in half the time
Copyright ©2023 Educative, Inc. All rights reserved.
ERROR: Command errored out with exit status 1 mysqlclient: I was installing mysqlclient for my new Django project in my newly installed Ubuntu Linux. And after doing pip install mysqlclient, I got an error of ERROR: Command errored out with exit status 1:
(env) [email protected]:~/Projects/aeck$ pip3 install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-2.0.3.tar.gz (88 kB)
ERROR: Command errored out with exit status 1:
command: /home/codie/Projects/aeck/env/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-4_d_xjb9/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-4_d_xjb9/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-4_d_xjb9/mysqlclient/pip-egg-info
cwd: /tmp/pip-install-4_d_xjb9/mysqlclient/
Complete output (15 lines):
/bin/sh: 1: mysql_config: not found
/bin/sh: 1: mariadb_config: not found
/bin/sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-4_d_xjb9/mysqlclient/setup.py", line 15, in <module>
metadata, options = get_config()
File "/tmp/pip-install-4_d_xjb9/mysqlclient/setup_posix.py", line 70, in get_config
libs = mysql_config("libs")
File "/tmp/pip-install-4_d_xjb9/mysqlclient/setup_posix.py", line 31, in mysql_config
raise OSError("{} not found".format(_mysql_config_path))
OSError: mysql_config not found
mysql_config --version
mariadb_config --version
mysql_config --libs
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Also, solve your issue for psycopg2 error install ubuntu
So, how can we fix the issue of /bin/sh: 1: mysql_config: not found or /bin/sh: 1: mariadb_config: not found.
I did some research and after digging the web for 15 minutes, I got the fix for this issue.
To fix the issue of pip install mysqlclient error, you just need to copy the below codes and execute them in your bash-shell.
Install the python3-dev package
python-dev
contains the header files that the system needs to build Python extensions. It is used by lxml
because it includes Python C extensions for high performance.
sudo apt-get install python3-dev
lxml
is a Python C-API extension that is compiled when we run the command pip install lxml
.
The lxml sources have at least something like #include <Python.h>
in the code. The compiler looks for the header file Python.h
during compilation, hence those header files need to be on your system such that they can be found.
Also, solve: Django MySQLClient pip compile failure on Linux
(env) [email protected]:~/Projects/aeck$ sudo apt-get install libmysqlclient-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libssl-dev libssl1.1
Suggested packages:
libssl-doc
The following NEW packages will be installed:
libmysqlclient-dev libssl-dev
The following packages will be upgraded:
libssl1.1
1 upgraded, 2 newly installed, 0 to remove and 107 not upgraded.
Need to get 4,437 kB of archives.
After this operation, 17.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 libssl1.1 amd64 1.1.1f-1ubuntu2.3 [1,320 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 libssl-dev amd64 1.1.1f-1ubuntu2.3 [1,582 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 libmysqlclient-dev amd64 8.0.23-0ubuntu0.20.04.1 [1,536 kB]
Fetched 4,437 kB in 5s (921 kB/s)
Preconfiguring packages ...
(Reading database ... 132596 files and directories currently installed.)
Preparing to unpack .../libssl1.1_1.1.1f-1ubuntu2.3_amd64.deb ...
Unpacking libssl1.1:amd64 (1.1.1f-1ubuntu2.3) over (1.1.1f-1ubuntu2.1) ...
Selecting previously unselected package libssl-dev:amd64.
Preparing to unpack .../libssl-dev_1.1.1f-1ubuntu2.3_amd64.deb ...
Unpacking libssl-dev:amd64 (1.1.1f-1ubuntu2.3) ...
Selecting previously unselected package libmysqlclient-dev.
Preparing to unpack .../libmysqlclient-dev_8.0.23-0ubuntu0.20.04.1_amd64.deb ...
Unpacking libmysqlclient-dev (8.0.23-0ubuntu0.20.04.1) ...
Setting up libssl1.1:amd64 (1.1.1f-1ubuntu2.3) ...
Setting up libssl-dev:amd64 (1.1.1f-1ubuntu2.3) ...
Setting up libmysqlclient-dev (8.0.23-0ubuntu0.20.04.1) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
Installing dependency for mysqlclient
Now, you just need to install the dependency for mysqlclient called libmysqlclient-dev
.
sudo apt-get install libmysqlclient-dev
libmysqlclient-dev
is a package that provides all the essential dependencies and resources to the system required for the functioning of mysqlclient.
For Python3.9
sudo apt-get install python3.9-dev build-essential
Finally, pip install mysqlclient
Now, you can install mysqlclient with no tension.
python3 -m pip install mysqlclient
or
pip3 install mysqlclient
I’m using Python 3.5.1 and pip 8.0.2 on OS X that I installed using pyenv. When installing mysqlclient I get the error «Failed building wheel for mysqlclient». The following is my terminal output.
$ pip install mysqlclient==1.3.7
Collecting mysqlclient==1.3.7
Using cached mysqlclient-1.3.7.tar.gz
Building wheels for collected packages: mysqlclient
Running setup.py bdist_wheel for mysqlclient ... error
Complete output from command /Users/brento/.virtualenvs/pears-py3/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/private/var/folders/q8/nr7dx6213ld0p451xxqm138h0000gp/T/pip-build-rayxd4we/mysqlclient/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('rn', 'n'), __file__, 'exec'))" bdist_wheel -d /var/folders/q8/nr7dx6213ld0p451xxqm138h0000gp/T/tmpvg5zyj7upip-wheel- --python-tag cp35:
running bdist_wheel
running build
running build_py
creating build
creating build/lib.macosx-10.11-x86_64-3.5
copying _mysql_exceptions.py -> build/lib.macosx-10.11-x86_64-3.5
creating build/lib.macosx-10.11-x86_64-3.5/MySQLdb
copying MySQLdb/__init__.py -> build/lib.macosx-10.11-x86_64-3.5/MySQLdb
copying MySQLdb/compat.py -> build/lib.macosx-10.11-x86_64-3.5/MySQLdb
copying MySQLdb/converters.py -> build/lib.macosx-10.11-x86_64-3.5/MySQLdb
copying MySQLdb/connections.py -> build/lib.macosx-10.11-x86_64-3.5/MySQLdb
copying MySQLdb/cursors.py -> build/lib.macosx-10.11-x86_64-3.5/MySQLdb
copying MySQLdb/release.py -> build/lib.macosx-10.11-x86_64-3.5/MySQLdb
copying MySQLdb/times.py -> build/lib.macosx-10.11-x86_64-3.5/MySQLdb
creating build/lib.macosx-10.11-x86_64-3.5/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.11-x86_64-3.5/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.macosx-10.11-x86_64-3.5/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.11-x86_64-3.5/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.macosx-10.11-x86_64-3.5/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.11-x86_64-3.5/MySQLdb/constants
copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.11-x86_64-3.5/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.11-x86_64-3.5/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.macosx-10.11-x86_64-3.5
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -Dversion_info=(1,3,7,'final',1) -D__version__=1.3.7 -I/usr/local/Cellar/mysql/5.7.10/include/mysql -I/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/include/python3.5m -c _mysql.c -o build/temp.macosx-10.11-x86_64-3.5/_mysql.o -fno-omit-frame-pointer
clang -bundle -undefined dynamic_lookup -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk build/temp.macosx-10.11-x86_64-3.5/_mysql.o -L/usr/local/Cellar/mysql/5.7.10/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.11-x86_64-3.5/_mysql.cpython-35m-darwin.so
installing to build/bdist.macosx-10.11-x86_64/wheel
running install
running install_lib
creating build/bdist.macosx-10.11-x86_64
creating build/bdist.macosx-10.11-x86_64/wheel
copying build/lib.macosx-10.11-x86_64-3.5/_mysql.cpython-35m-darwin.so -> build/bdist.macosx-10.11-x86_64/wheel
copying build/lib.macosx-10.11-x86_64-3.5/_mysql_exceptions.py -> build/bdist.macosx-10.11-x86_64/wheel
creating build/bdist.macosx-10.11-x86_64/wheel/MySQLdb
copying build/lib.macosx-10.11-x86_64-3.5/MySQLdb/__init__.py -> build/bdist.macosx-10.11-x86_64/wheel/MySQLdb
copying build/lib.macosx-10.11-x86_64-3.5/MySQLdb/compat.py -> build/bdist.macosx-10.11-x86_64/wheel/MySQLdb
copying build/lib.macosx-10.11-x86_64-3.5/MySQLdb/connections.py -> build/bdist.macosx-10.11-x86_64/wheel/MySQLdb
creating build/bdist.macosx-10.11-x86_64/wheel/MySQLdb/constants
copying build/lib.macosx-10.11-x86_64-3.5/MySQLdb/constants/__init__.py -> build/bdist.macosx-10.11-x86_64/wheel/MySQLdb/constants
copying build/lib.macosx-10.11-x86_64-3.5/MySQLdb/constants/CLIENT.py -> build/bdist.macosx-10.11-x86_64/wheel/MySQLdb/constants
copying build/lib.macosx-10.11-x86_64-3.5/MySQLdb/constants/CR.py -> build/bdist.macosx-10.11-x86_64/wheel/MySQLdb/constants
copying build/lib.macosx-10.11-x86_64-3.5/MySQLdb/constants/ER.py -> build/bdist.macosx-10.11-x86_64/wheel/MySQLdb/constants
copying build/lib.macosx-10.11-x86_64-3.5/MySQLdb/constants/FIELD_TYPE.py -> build/bdist.macosx-10.11-x86_64/wheel/MySQLdb/constants
copying build/lib.macosx-10.11-x86_64-3.5/MySQLdb/constants/FLAG.py -> build/bdist.macosx-10.11-x86_64/wheel/MySQLdb/constants
copying build/lib.macosx-10.11-x86_64-3.5/MySQLdb/constants/REFRESH.py -> build/bdist.macosx-10.11-x86_64/wheel/MySQLdb/constants
copying build/lib.macosx-10.11-x86_64-3.5/MySQLdb/converters.py -> build/bdist.macosx-10.11-x86_64/wheel/MySQLdb
copying build/lib.macosx-10.11-x86_64-3.5/MySQLdb/cursors.py -> build/bdist.macosx-10.11-x86_64/wheel/MySQLdb
copying build/lib.macosx-10.11-x86_64-3.5/MySQLdb/release.py -> build/bdist.macosx-10.11-x86_64/wheel/MySQLdb
copying build/lib.macosx-10.11-x86_64-3.5/MySQLdb/times.py -> build/bdist.macosx-10.11-x86_64/wheel/MySQLdb
running install_egg_info
running egg_info
writing top-level names to mysqlclient.egg-info/top_level.txt
writing dependency_links to mysqlclient.egg-info/dependency_links.txt
writing mysqlclient.egg-info/PKG-INFO
warning: manifest_maker: standard file '-c' not found
reading manifest file 'mysqlclient.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'mysqlclient.egg-info/SOURCES.txt'
Copying mysqlclient.egg-info to build/bdist.macosx-10.11-x86_64/wheel/mysqlclient-1.3.7-py3.5.egg-info
running install_scripts
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/q8/nr7dx6213ld0p451xxqm138h0000gp/T/pip-build-rayxd4we/mysqlclient/setup.py", line 21, in <module>
setuptools.setup(**metadata)
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/Users/brento/.virtualenvs/pears-py3/lib/python3.5/site-packages/wheel/bdist_wheel.py", line 213, in run
archive_basename = self.get_archive_basename()
File "/Users/brento/.virtualenvs/pears-py3/lib/python3.5/site-packages/wheel/bdist_wheel.py", line 161, in get_archive_basename
impl_tag, abi_tag, plat_tag = self.get_tag()
File "/Users/brento/.virtualenvs/pears-py3/lib/python3.5/site-packages/wheel/bdist_wheel.py", line 155, in get_tag
assert tag == supported_tags[0]
AssertionError
----------------------------------------
Failed building wheel for mysqlclient
Running setup.py clean for mysqlclient
Failed to build mysqlclient
Installing collected packages: mysqlclient
Found existing installation: mysqlclient 1.3.6
Uninstalling mysqlclient-1.3.6:
Successfully uninstalled mysqlclient-1.3.6
Running setup.py install for mysqlclient ... done
Successfully installed mysqlclient-1.3.7
Willing to solve pip install mysqlclient? It really sucks while installing in CMD because it requires up to two-three extra functions that must available.
pip is the friendly and easy way to install MySQL clients like mysqldump, which can be used for creating or restoring backup databases.
It’s also possible with this library in Python 3 run MySQL queries on localhost without any authentication required (you’ll need an administrative account).
So guys! before going further you have to understand why pip not getting installed?
What exactly problem with that it getting suck?
Let’s get started!
Contents
- 1 Fix pip install mysqlclient
- 1.1 pip install mysqlclient
- 1.2 pip install mysqlclient in Linux
- 1.3 Install directly from Github
- 2 How To Fix pip install mysqlclient
There is one command that helps to install but I do not think it will really work on every laptop or computer?
Copy out the command and run in CMD
pip install mysqlclient
If you write the above command it will return you an error so you should above from that one by the following command:
python -m pip install mysqlclient==1.4.2.post1
Stilling same? I think it is but do not worry about it. In the below-mentioned command is the latest version.
pip install mysqlclient==2.0.3
And last but not least if you are still fetching an error. I hope the latest version must help you otherwise use the following command to install mysqlclient.
pip install mysqlclient==1.3.1
Note: Keep in mind that the oldest versions are no more so, that is why you are to check out the latest version. Here
pip install mysqlclient in Linux
For Linux:
$ sudo apt-get install python3-dev default-libmysqlclient-dev build-essential
Install directly from Github
Take a link from Github
- Copy the link.
- Paste into CMD.
- Before pasting the link write down these commands.
- python then the GitHub link which you copied and then setup.py.
- If none of the above-mentioned ideas will work anymore on your computer or laptop then download the zip file from download Github.
- Extract anywhere.
- Go to cmd.
- Do dir to check the folders, and then go to mysqlclient folder, there is one file that name is: setup.py.
- And then do cd to go to the folder.
- Run the command: python setup.py install.
- Almost done!
Read more: SyntaxError: invalid syntax when upgrading pip in Python.
How To Fix pip install mysqlclient
-
#1
I’m trying to set up a Python application using the cPanel interface. I’ve successfully created it and added the requirements.txt file.
But when I click the «Run Pip Install» button, and select «requirements.txt», after it spins for a while I get this error message:
error: subprocess-exited-with-error
× python setup.py bdist_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.
ERROR: Failed building wheel for mysqlclient
error: subprocess-exited-with-error× Running setup.py install for mysqlclient 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.
error: legacy-install-failure× Encountered error while trying to install package.
╰─> mysqlclientnote: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
The requirements.txt file lists
and my Python app is set to use python 3.8.6.
How can I complete the installation?
-
#2
Hey there! cPanel doesn’t officially provide support for Python tools as outlined in our notice at the tope of this documentation page:
but have you tried making sure the mysql-community-devel or mysql-devel package is installed? If that is missing, Pip may not be able to build the mysqlclient properly.
This seems to be a relatively recent error as most information I found about this issue was created within the last 6 months. Here is one example:
-
#3
Thanks. In the end I changed from using mysqlclient to mysql-connector-python which installed OK.
A shame the former didn’t work. If I wanted to try again, how would I install the mysql-community-devel or mysql-devel packages on cPanel?
-
#4
Thanks. In the end I changed from using mysqlclient to mysql-connector-python which installed OK.
A shame the former didn’t work. If I wanted to try again, how would I install the mysql-community-devel or mysql-devel packages on cPanel?
Depends on OS but yum should work for AlmaLinux as well or you can use
dnf install [pkg-name]
yum install [pkg-name]
yum install mysql-devel
yum install mysql-community-devel
or
dnf install mysql-devel
dnf install mysql-community-devel
[[email protected] ~]# yum install mysql-community-devel
Last metadata expiration check: 1:53:02 ago on Wed 11 May 2022 11:43:10 PM CDT.
Package mysql-community-devel-8.0.29-1.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[[email protected] ~]# ]yum install mysql-devel
bash: ]yum: command not found
[[email protected] ~]# yum install mysql-devel
Last metadata expiration check: 1:54:11 ago on Wed 11 May 2022 11:43:10 PM CDT.
Package mysql-community-devel-8.0.29-1.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[[email protected] ~]
-
#5
Thank you! I’m a bit wary of installing extra stuff like this, given I’m setting this site up on someone else’s server for them. But it’s useful to know what to do if mysql-connector-python doesn’t work out (or for anyone else finding this page and wondering what to do!).
-
#6
I’m glad to hear that worked well!