Ubuntu 17: Can't install mysqlclient - python

Trying to follow a Django tutorial but I cannot install mysqlclient.
The tutorial claims that I can do so with the following command:
pip install mysqlclient
but this generates this error:
Collecting mysqlclient Using cached mysqlclient-1.3.12.tar.gz
Complete output from command python setup.py egg_info:
/bin/sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-rrolctwh/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "/tmp/pip-build-rrolctwh/mysqlclient/setup_posix.py", line 44, in get_config
libs = mysql_config("libs_r")
File "/tmp/pip-build-rrolctwh/mysqlclient/setup_posix.py", line 26, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
OSError: mysql_config not found
---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-rrolctwh/mysqlclient/
I have the most up-to-date pip and virtualenv installed.
I would like to be able to install mysqlclient so that I may continue with the tutorial.

You should also install the mysql and python development headers and libraries:
https://github.com/PyMySQL/mysqlclient-python#prerequisites

I was facing the same problems, but following the instructions in the Official mysqlclient documentation fixed it for me
but just to clarify I was running python 3.5 from a virtual environment
and after installing the prerequisites, it all worked fine

The following solved it for me :
You may need to install the Python 3 and MySQL development headers and libraries like so:
$ sudo apt-get install python3-dev default-libmysqlclient-dev build-essential # Debian / Ubuntu
% sudo yum install python3-devel mysql-devel # Red Hat / CentOS
Then you can install mysqlclient via pip now:
$ pip install mysqlclient
Source : https://github.com/PyMySQL/mysqlclient#prerequisites

I had also similar issue on Centos 6, where there was a problem with mysql migration to maria, I had some conflicts, but finally I installed:
yum list installed |grep MariaDB
MariaDB-client.x86_64 10.2.7-1.el6 #bull
MariaDB-common.x86_64 10.2.7-1.el6 #bull
MariaDB-compat.x86_64 10.2.7-1.el6 #bull
MariaDB-devel.x86_64 10.2.7-1.el6 #bull
MariaDB-server.x86_64 10.2.7-1.el6 #bull
And the issue was resolved.

Related

mysqlclient-1.4.6 now fails to install (Python 3.9) when it did under 3.6

When I try to use pip3 install -r requirements.txt now that my virtualenv (and my host Python version) is somehow 3.9 instead of 3.6 as it used to be, installation of mysqlclient=1.4.6 now fails this way:
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/78/m6t5zwl12lz2l9gjd_44x57w0000gn/T/pip-install-6d8h889b/mysqlclient_646d323b983840789a470475ee860b29/setup.py", line 16, in <module>
metadata, options = get_config()
File "/private/var/folders/78/m6t5zwl12lz2l9gjd_44x57w0000gn/T/pip-install-6d8h889b/mysqlclient_646d323b983840789a470475ee860b29/setup_posix.py", line 61, in get_config
libs = mysql_config("libs")
File "/private/var/folders/78/m6t5zwl12lz2l9gjd_44x57w0000gn/T/pip-install-6d8h889b/mysqlclient_646d323b983840789a470475ee860b29/setup_posix.py", line 29, in mysql_config
raise EnvironmentError("%s not found" % (_mysql_config_path,))
OSError: mysql_config not found
The mysql_config script does exist on this system as: /usr/local/mysql-5.7.16-osx10.11-x86_64/bin/mysql_config but I don't know how it is supposed to be located by the installer. And, I don't know why it's failing now when it didn't fail then. Please advise.
It seems to have failed while trying to run several mysql related binaries from a python script. Try to set your system's PATH environment to allow the install script to find the mysql related binaries.
PATH="/usr/local/mysql-5.7.16-osx10.11-x86_64/bin:$PATH" pip3 install -r requirements.txt
P.S. I tried to reproduce the installation with the same Python 3.9, mysqlclient 1.4.6 in my Mac environment, and it was installed normally.
$ python --version
Python 3.9.4
$ which mysql_config
/opt/homebrew/opt/mysql#5.7/bin/mysql_config
$ python3 -m venv .venv
$ . .venv/bin/activate
$ pip install mysqlclient==1.4.6
Collecting mysqlclient==1.4.6
Downloading mysqlclient-1.4.6.tar.gz (85 kB)
|████████████████████████████████| 85 kB 1.8 MB/s
Using legacy 'setup.py install' for mysqlclient, since package 'wheel' is not installed.
Installing collected packages: mysqlclient
Running setup.py install for mysqlclient ... done
Successfully installed mysqlclient-1.4.6
I found my own answer!
In this case:
export PATH=/usr/local/mysql-5.7.6-0sx10.11-x86_64/bin:$PATH
(This being the directory where I separately discovered that the mysql_config script is installed on my computer – see above.) The problem was that the file wasn't in the $PATH. The above command adds it to the beginning of the path list for the duration of the present terminal session.
... then repeat the pip3 install command as above, and now it works.

How to install MySQL-python on Amazon Web Services EC2 instance?

I have a EC2 instance created on AWS and use PuTTY to connect to it.
I'm unable to install MySQL-python using python pip command as follows:
pip install MySQL-python(via root privileges)
Here is the console output of the error
Collecting MySQL-python
Using cached MySQL-python-1.2.5.zip
Complete output from command python setup.py egg_info:
sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "/tmp/pip-build-JGbAEI/MySQL-python/setup.py", line 17, in <module>
metadata, options = get_config()
File "/tmp/pip-build-JGbAEI/MySQL-python/setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "/tmp/pip-build-JGbAEI/MySQL-python/setup_posix.py", line 25, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-JGbAEI/MySQL-python
However I'm able to install other packages using pip
Please Guide.
mysql_config is available after installation of the following package on Amazon Linux:
sudo yum install -y mysql-devel
It looks like mysql_config is missing, so make sure mysql_config is really installed.
For example on Debian/Ubuntu you must install the package:
sudo apt-get install libmysqlclient-dev

Error with pip install MySQL-python [duplicate]

This question already has answers here:
pip install mysql-python fails with EnvironmentError: mysql_config not found
(24 answers)
Closed 3 years ago.
I have been trying for a few days to fix this, looking at other questions but I can't find a question wth the same error that I am getting.
I have been attempting to follow this tutorial https://realpython.com/learn/start-django/ and get to this point:
Database settings
First, install MySQL-python, which is a database connector for Python:
$ pip install MySQL-python
Everything has worked okay up to here but when I try and install MySQL-python I get the following error:
(env) Camerons-MacBook-Pro:django15_project camrail$ pip install MySQL-python
Collecting MySQL-python
Using cached MySQL-python-1.2.5.zip
Complete output from command python setup.py egg_info:
sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/3v/czm4shrx0yg5jts39qktf6t00000gn/T/pip-build-2rNsQQ/MySQL-python/setup.py", line 17, in <module>
metadata, options = get_config()
File "/private/var/folders/3v/czm4shrx0yg5jts39qktf6t00000gn/T/pip-build-2rNsQQ/MySQL-python/setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "/private/var/folders/3v/czm4shrx0yg5jts39qktf6t00000gn/T/pip-build-2rNsQQ/MySQL-python/setup_posix.py", line 25, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/3v/czm4shrx0yg5jts39qktf6t00000gn/T/pip-build-2rNsQQ/MySQL-python/
(env) Camerons-MacBook-Pro:django15_project camrail$
I found this answer https://opensourcehacker.com/2011/03/02/installing-mysql-python-connector-on-osx/ that says the MySQL utilities are not made available, so I followed their advice to fix it but to no avail. I have also tried installing developer tools xcode-select --install as some have suggested. I have tried reinstalling ez_setup.
Not really sure where to go from here, any help greatly appreciated.
In my opinions mysql_config is missing on your system or the installer could not find it. Please Be sure mysql_config is really installed.
For instance,
On Debian/Ubuntu, You must install the package:
sudo apt-get install libmysqlclient-dev
Running Mac OSX Mountain Lion, I simply ran this in terminal to fix:
export PATH=$PATH:/usr/local/mysql/bin
This is the quickest fix I found.
I was also getting the same error while installing the mysql package by pip But after installing libmysqlclient-dev
sudo apt install libmysqlclient-dev
pip install mysql
Now it worked for me..
verified:
import mysql
did not find any error, Means got installed successfully and working
properly
Check your mysql configuration file using this:
mysql_config
Now you should get an output something like this:
mysql_config
Usage: /usr/bin/mysql_config [OPTIONS]
Compiler: GNU 6.3.0
Options:
--cflags [-I/usr/include/mysql ]
--cxxflags [-I/usr/include/mysql ]
--include [-I/usr/include/mysql]
--libs [-L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -latomic -ldl]
--libs_r [-L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -latomic -ldl]
--plugindir [/usr/lib/mysql/plugin]
--socket [/var/run/mysqld/mysqld.sock]
--port [0]
--version [5.7.18]
--libmysqld-libs [-L/usr/lib/x86_64-linux-gnu -lmysqld -lpthread -lz -lm -lrt -latomic -lcrypt -ldl -laio -llz4 -lnuma]
--variable=VAR VAR is one of:
pkgincludedir [/usr/include/mysql]
pkglibdir [/usr/lib/x86_64-linux-gnu]
plugindir [/usr/lib/mysql/plugin]
Ideally it should contain libmysqld-libs option. If it is not there, as it was not there in my case, you can assume that your mysql is broken.
In this case you can write this configuration to config file directly
If you are using Windows OS download and install mysql-python directly from here .
Not sure if it useful. But it help me to solve the problem.
apt-get install build-essential zlib1g zlib1g-dev zlibc libxml2 libxml2-dev
For completeness sake, on Debian Stretch the pkg is now called default-libmysqlclient-dev.
sudo apt-get install default-libmysqlclient-dev
I run the following commands and it worked smooth in Ubuntu 17.10
sudo apt-get install libmysqlclient-dev
pip3 install mysqlclient

Unable to do pip install mysql-python on virtualenv

I use macports and I have successfully install mysql5 using macports, and my python also managed by macports. Currently I am trying to do pip install mysql-python on my virtualenv but I am getting an error which says, mysql_config not found:
~/code]$pip install mysql-python
Downloading/unpacking mysql-python
Running setup.py egg_info for package mysql-python
sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "~/myVirtualEnv/build/mysql-python/setup.py", line 18, 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
Complete output from command python setup.py egg_info:
sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "~/myVirtualEnv/build/mysql-python/setup.py", line 18, 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
I read many google examples but more I read helped me to confuse myself further.
Looks like macport have had a issue but it has been closed for while.. http://trac.macports.org/ticket/6982
MacPort creates a symbolic link mysql_config5 in /opt/local/bin to /opt/local/lib/mysql5/bin/mysql_config. Create another link called mysql_config.
cd /opt/local/bin
sudo ln -s /opt/local/lib/mysql5/bin/mysql_config .
I seem to recall having to create a my.cnf too. By default Mac OSX uses all the defaults and doesn't create a my.cnf, create one /etc/my.cnf, it can be trivial.
Mine is just:
[mysqld]
bind-address = 0.0.0.0
port = 3306
mysql_config is an executable that it is in the libmysqlclient package so you need to install. On Deb systems you could install this using
sudo apt-get install libmysqlclient-dev
in RPM
RPM equivalent: sudo yum install mysql-devel
in mac maybe
Macports - port install mysql5 +server
Add /opt/local/lib/mysql5/bin/ to your command search path and then rerun the "pip install" command should solve the problem.
export PATH=/opt/local/lib/mysql55/bin/:$PATH
pip install mysql-python
I encountered the same issue, and solved it:
Install mysql. If you have installed it, ignore this step.
yum install mysql-devel
If you encountered error like Python.h: No such file or directory,
run yum -y install python-devel

Oursql insallation failing wtih "cython not found"

Trying to install oursql driver for python3x and sqlalchemy0.8 on ubuntu 12.10. It fails with the following error.
sudo pip-3.2 install oursql
Downloading/unpacking oursql
Running setup.py egg_info for package oursql
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/tmp/pip-build/oursql/setup.py", line 53
print "cython not found, using previously-cython'd .c file."
^
SyntaxError: invalid syntax
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/tmp/pip-build/oursql/setup.py", line 53
print "cython not found, using previously-cython'd .c file."
^
SyntaxError: invalid syntax
When I try to install cython I seem to already have it:
sudo pip-3.2 install cython
Requirement already satisfied (use --upgrade to upgrade): cython in /usr/local/lib/python3.2/dist-packages
Cleaning up.
What can I do to make it run?
Had the same error when running pip-3.2.
This is how I made it work:
Created my env using python-3.2:
virtualenv -p /usr/bin/python3.2
Installed the required packages:
sudo apt-get install python-dev
sudo apt-get install libmysqlclient-dev
Then installed:
sudo pip install cython
sudo pip install oursql
Edit1:
I was able to get pass you error with my above recomendations, but i was wrong (python3.2 was unable to read oursql). I tried the following and was able to make a connection:
First:
sudo apt-get install python3.2-dev
Then installed oursql for Python 3 from source (as suggested by it's maintainer here):
Get the Python 3 version of oursql from here and compile it from source (Don't have enough reputation to post the link, just go to oursql official site for installation instructions).
The maintainers have two packages, one for python 2.x and one for python 3.x, you should run:
pip install oursql3
There is nothing about cython.
You just encoutered a syntax error in print, because the print statement doesn't use brackets there. They were optional in Python 2's print statement, but are required in Python 3's print() function.
install it manually - reqs: python-dev, cython
then download oursql package (try 0.9.3.zip)
and
python setup.py install

Categories