How to install mysqlclient in python? - python

I am new to Python, coming from Java and JS background,
I've installed Python and Pip in my local machine,
I am trying to learn Django, using MySQL,
But I am unable to install the mysqlclient using pip,
I used the following command to do so -
pip install mysqlclient
It's giving the following error -
Collecting mysqlclient
Using cached https://files.pythonhosted.org/packages/4d/38/c5f8bac9c50f3042c8f05615f84206f77f03db79781db841898fde1bb284/mysqlclient-1.4.4.tar.gz
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/ms/q8s67d8n09q59mbpshz3dq9m0000gn/T/pip-install-nk55db_s/mysqlclient/setup.py'"'"'; __file__='"'"'/private/var/folders/ms/q8s67d8n09q59mbpshz3dq9m0000gn/T/pip-install-nk55db_s/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
cwd: /private/var/folders/ms/q8s67d8n09q59mbpshz3dq9m0000gn/T/pip-install-nk55db_s/mysqlclient/
Complete output (12 lines):
/bin/sh: mysql_config: command not found
/bin/sh: mariadb_config: command not found
/bin/sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/ms/q8s67d8n09q59mbpshz3dq9m0000gn/T/pip-install-nk55db_s/mysqlclient/setup.py", line 16, in <module>
metadata, options = get_config()
File "/private/var/folders/ms/q8s67d8n09q59mbpshz3dq9m0000gn/T/pip-install-nk55db_s/mysqlclient/setup_posix.py", line 61, in get_config
libs = mysql_config("libs")
File "/private/var/folders/ms/q8s67d8n09q59mbpshz3dq9m0000gn/T/pip-install-nk55db_s/mysqlclient/setup_posix.py", line 29, in mysql_config
raise EnvironmentError("%s not found" % (_mysql_config_path,))
OSError: mysql_config not found
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Screenshot -

I am solve error following process
Python 3.8.0
First install in Homebraw type following command. type this command in terminal
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install mariadb-connector-c
pip install mysqlclient
more issues follow this tutorial
https://medium.com/#MrWeeble/homebrew-on-mac-and-pythons-mysqlclient-ea44fa300e70

mysqlclient requires additional c libraires.
For linux (Debian):
$ sudo apt-get install python3-dev default-libmysqlclient-dev build-essential
For Mac:
$ brew install mysql
Further reading at the home page

Related

Trouble installing MySQL client on Mac

Using cached mysqlclient-1.3.0.tar.gz (76 kB)
ERROR: Command errored out with exit status 1:
command: /Users/mr.sallam/.local/share/virtualenvs/Admission_System-h6ReVRNX/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/58/khmzr9l90hx237729cjz2ct00000gn/T/pip-install-cn6qvsqm/mysqlclient_c82e6a9eeefe4d66bf9960f11336d0db/setup.py'"'"'; __file__='"'"'/private/var/folders/58/khmzr9l90hx237729cjz2ct00000gn/T/pip-install-cn6qvsqm/mysqlclient_c82e6a9eeefe4d66bf9960f11336d0db/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/58/khmzr9l90hx237729cjz2ct00000gn/T/pip-pip-egg-info-186pdzul
cwd: /private/var/folders/58/khmzr9l90hx237729cjz2ct00000gn/T/pip-install-cn6qvsqm/mysqlclient_c82e6a9eeefe4d66bf9960f11336d0db/
Complete output (10 lines):
/bin/sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/58/khmzr9l90hx237729cjz2ct00000gn/T/pip-install-cn6qvsqm/mysqlclient_c82e6a9eeefe4d66bf9960f11336d0db/setup.py", line 17, in <module>
metadata, options = get_config()
File "/private/var/folders/58/khmzr9l90hx237729cjz2ct00000gn/T/pip-install-cn6qvsqm/mysqlclient_c82e6a9eeefe4d66bf9960f11336d0db/setup_posix.py", line 47, in get_config
libs = mysql_config("libs_r")
File "/private/var/folders/58/khmzr9l90hx237729cjz2ct00000gn/T/pip-install-cn6qvsqm/mysqlclient_c82e6a9eeefe4d66bf9960f11336d0db/setup_posix.py", line 29, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
OSError: mysql_config not found
----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/6a/91/bdfe808fb5dc99a5f65833b370818161b77ef6d1e19b488e4c146ab615aa/mysqlclient-1.3.0.tar.gz#sha256=06eb5664e3738b283ea2262ee60ed83192e898f019cc7ff251f4d05a564ab3b7 (from https://pypi.org/simple/mysqlclient/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement mysqlclient
ERROR: No matching distribution found for mysqlclient
As per the readme for mysqlclient, on macOS you will need to install mysql or mysql-client:
# Assume you are activating Python 3 venv
$ brew install mysql
$ pip install mysqlclient
If you don't want to install MySQL server, you can use mysql-client instead:
# Assume you are activating Python 3 venv
$ brew install mysql-client
$ echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.bash_profile
$ export PATH="/usr/local/opt/mysql-client/bin:$PATH"
$ pip install mysqlclient
On Mac
brew install mysql
Reference:
https://dev.mysql.com/doc/connector-python/en/connector-python-installation-binary.html
https://dev.mysql.com/doc/mysql-osx-excerpt/5.7/en/osx-installation-pkg.html
Have you considered installing pymysql, a pure Python MySQL driver?
Also, since it is purely pythonic, it is quite more cross compatible than c based MySQL connectors.
From terminal
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
HOMEBREW_NO_ENV_FILTERING=1 ACCEPT_EULA=Y brew install msodbcsql17 mssql-tools

pip install MySQL-python==1.2.5 not working [duplicate]

This question already has answers here:
pip install mysql-python fails with EnvironmentError: mysql_config not found
(24 answers)
Closed 2 years ago.
I'm trying to install MySQL-python with pip.
I'm using Python v2.7.18 and pip v20.3.4
I'm trying it with:
pip install MySQL-python==1.2.5
But it gives this error:
Defaulting to user installation because normal site-packages is not writeable
Collecting MySQL-python==1.2.5
Using cached MySQL-python-1.2.5.zip (108 kB)
ERROR: Command errored out with exit status 1:
command: /usr/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-zuV7aL/mysql-python/setup.py'"'"'; __file__='"'"'/tmp/pip-install-zuV7aL/mysql-python/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-TefBrj
cwd: /tmp/pip-install-zuV7aL/mysql-python/
Complete output (10 lines):
sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-zuV7aL/mysql-python/setup.py", line 17, in <module>
metadata, options = get_config()
File "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "setup_posix.py", line 25, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
What am I doing wrong?
You need to install dev libs for mysql client:
sudo apt-get install libmysqlclient-dev

How to Correctly install MySQL module in Python

I am new to coding and ubuntu, and I am trying to insert some data to MySQL using Python, but I am having some error in installing the mysql module.
I am having this error:
**pip install mysql**
Defaulting to user installation because normal site-packages is not writeable
Collecting mysql
Using cached mysql-0.0.2.tar.gz (1.9 kB)
Collecting mysqlclient
Using cached mysqlclient-2.0.2.tar.gz (88 kB)
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-8pt10wd4/mysqlclient_5e8d8ff6d905420ea115c27e23267248/setup.py'"'"'; __file__='"'"'/tmp/pip-install-8pt10wd4/mysqlclient_5e8d8ff6d905420ea115c27e23267248/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-ocgktfp6
cwd: /tmp/pip-install-8pt10wd4/mysqlclient_5e8d8ff6d905420ea115c27e23267248/
Complete output (12 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-8pt10wd4/mysqlclient_5e8d8ff6d905420ea115c27e23267248/setup.py", line 15, in <module>
metadata, options = get_config()
File "/tmp/pip-install-8pt10wd4/mysqlclient_5e8d8ff6d905420ea115c27e23267248/setup_posix.py", line 65, in get_config
libs = mysql_config("libs")
File "/tmp/pip-install-8pt10wd4/mysqlclient_5e8d8ff6d905420ea115c27e23267248/setup_posix.py", line 31, in mysql_config
raise OSError("{} not found".format(_mysql_config_path))
OSError: mysql_config not found
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
pip install mysql-connector-python try this , if you are still facing the issue, check your python version, make sure it is python3.8 and above.
Hello and welcome to Python! A popular library used for interacting with MySQL database servers is "PyMySQL" and this can be found at: https://pypi.org/project/PyMySQL/
Installation Command:
pip install pymysql
You can view example usage here: https://pypi.org/project/PyMySQL/#example

ERROR: Command errored out with exit status 1

I tried:
pip3 install -r requirements.txt
Here's the error I received:
Command "python setup.py egg_info" failed with error code 1 in
C:\Users\Admin\AppData\Local\Temp\pip-install-6c3rea1s\pycocotools\
You are using pip version 19.0.3, however version 20.0.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip'
command.
So, I tried:
pip install --upgrade pip
and
install pip3 install -r requirements.txt
That resulted in more errors:
ERROR: Command errored out with exit status 1: command:
'c:\users\admin\appdata\local\programs\python\python37-32\python.exe'
-c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Admin\\AppData\\Local\\Temp\\pip-install-epmkeh4g\\pycocotools\\setup.py'"'"';
__file__='"'"'C:\\Users\\Admin\\AppData\\Local\\Temp\\pip-install-epmkeh4g\\pycocotools\\setup.py'"'"';f=getattr(tokenize,
'"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"',
'"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))'
egg_info --egg-base
'C:\Users\Admin\AppData\Local\Temp\pip-install-epmkeh4g\pycocotools\pip-egg-info'
cwd:
C:\Users\Admin\AppData\Local\Temp\pip-install-epmkeh4g\pycocotools\
Complete output (5 lines): Traceback (most recent call last):
File "<string>", line 1, in <module> File
"C:\Users\Admin\AppData\Local\Temp\pip-install-epmkeh4g\pycocotools\setup.py",
line 2, in <module> from Cython.Build import cythonize
ModuleNotFoundError: No module named 'Cython'
---------------------------------------- ERROR: Command errored out
with exit status 1: python setup.py egg_info Check the logs for full
command output.
I deleted the folder and re-install, but the results remained the same.
This is a bug in pycocotools. The bug was fixed in 2017 but it seems the fix didn't get into release 2.0 in 2018 (I guess the release process is also buggy).
There is also another similar bug in setup.py — it imports numpy before installing it.
There is no simple workarounds for these bugs using requirements.txt. You need to install the required modules before installing pycocotools:
pip install Cython numpy
pip install -r requirements.txt

Error messages when i want to pip install mysql-python and mysqlclient with MacOS

I'm currently working on a project using Django with python2.7 but each time I try pip install mysqsl I get this error messages
"" ERROR: Command errored out with exit status 1:
command: 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/jb/4wfxz94x599f8rnhtgkbs92c0000gn/T/pip-install-FpxjOl/mysql-python/setup.py'"'"'; __file__='"'"'/private/var/folders/jb/4wfxz94x599f8rnhtgkbs92c0000gn/T/pip-install-FpxjOl/mysql-python/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/jb/4wfxz94x599f8rnhtgkbs92c0000gn/T/pip-install-FpxjOl/mysql-python/pip-egg-info
cwd: /private/var/folders/jb/4wfxz94x599f8rnhtgkbs92c0000gn/T/pip-install-FpxjOl/mysql-python/
Complete output (10 lines):
sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/jb/4wfxz94x599f8rnhtgkbs92c0000gn/T/pip-install-FpxjOl/mysql-python/setup.py", line 17, in <module>
metadata, options = get_config()
File "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "setup_posix.py", line 25, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.""
Any help please
Most likely you have not installed mysql on your machine.
MySQLdb is a python interface for mysql, but it is not mysql itself. And apparently MySQLdb needs the command 'mysql_config', so you need to install that first.
You can install MySQL with brew.
xcode-select --install
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Once you have brew installed:
brew install mysql
brew link mysql
pip install MySQL-python

Categories