0

I am using OS X Yosemite, Python 3.6.2 and basically went through every single stackoverflow post regarding installation of MySQL into flask.

I've tried pip install flask-mysqlDB which gives me the error

Collecting flask-mysqldb
  Using cached Flask-MySQLdb-0.2.0.tar.gz
Requirement already satisfied: Flask>=0.10 in ./venv/lib/python3.6/site-packages (from flask-mysqldb)
Collecting mysqlclient (from flask-mysqldb)
  Using cached mysqlclient-1.3.10.tar.gz
    Complete output from command python setup.py egg_info:
    /bin/sh: mysql_config: command not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/c4/y49xcq6j6jlcr_8yyckm75th0000gp/T/pip-build-32rvmlzy/mysqlclient/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "/private/var/folders/c4/y49xcq6j6jlcr_8yyckm75th0000gp/T/pip-build-32rvmlzy/mysqlclient/setup_posix.py", line 44, in get_config
        libs = mysql_config("libs_r")
      File "/private/var/folders/c4/y49xcq6j6jlcr_8yyckm75th0000gp/T/pip-build-32rvmlzy/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 /private/var/folders/c4/y49xcq6j6jlcr_8yyckm75th0000gp/T/pip-build-32rvmlzy/mysqlclient/

none of the sudo apt-get commands work because of my Mac version. Installed homebrew by brew install python and I am still unable to use the sudo apt-get command.

My pip list is

click (6.7)
Flask (0.12.2)
itsdangerous (0.24)
Jinja2 (2.9.6)
MarkupSafe (1.0)
mysql-connector-python-rf (2.2.2)
mysqlclient (1.3.10)
pip (9.0.1)
setuptools (28.8.0)
virtualenv (15.1.0)
Werkzeug (0.12.2)

Now I have an error saying:

Collecting MySQL-python
  Using cached MySQL-python-1.2.5.zip
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/c4/y49xcq6j6jlcr_8yyckm75th0000gp/T/pip-build-n8on2g_t/MySQL-python/setup.py", line 13, in <module>
        from setup_posix import get_config
      File "/private/var/folders/c4/y49xcq6j6jlcr_8yyckm75th0000gp/T/pip-build-n8on2g_t/MySQL-python/setup_posix.py", line 2, in <module>
        from ConfigParser import SafeConfigParser
    ModuleNotFoundError: No module named 'ConfigParser'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/c4/y49xcq6j6jlcr_8yyckm75th0000gp/T/pip-build-n8on2g_t/MySQL-python/
Robert
  • 301
  • 5
  • 12
  • If you can't use apt that is really a bigger problem you should resolve, and it's not related to Python. – BrenBarn Aug 11 '17 at 07:08
  • There are two different packages as explained herehttps://stackoverflow.com/questions/45521644/flask-flaskext-mysql-no-attribute-connection/45522011#45522011 – Nabin Aug 11 '17 at 09:35
  • @Nabin Thank you very much! I think I was able to install it as I got the message "Successfully installed flask-mysqldb-0.2.0" Ive got "Flask-MySQLdb (0.2.0)" in my pip list. MySQL is installed probably, right? – Robert Aug 11 '17 at 11:57

3 Answers3

2

Install MySQL package and dependencies

Ubuntu

 sudo apt-get install python-pip python-dev libmysqlclient-dev

Mac OS

 brew install mysql-connector-c

using PIP

 pip install MySQL-python

In Python 3, ConfigParser has been renamed to configparser . The package you are installing does not support Python 3.

so in Python 3

pip install configparser

in python 2

pip install ConfigParser
Kallz
  • 3,244
  • 1
  • 20
  • 38
  • @Kaliz I still get the same error as I tried both pip install configparser and ConfigParser. Requirement already satisfied: configparser in /Users/yuyaKawahara/Desktop/projects/venv/lib/python3.6/site-packages – Robert Aug 11 '17 at 07:44
  • @Robert install only one configparser or ConfigParser according to python your python version – Kallz Aug 11 '17 at 07:46
  • I'm using python3 so I installed configparser but I still get the same error. Tried the other way around but the same result... – Robert Aug 11 '17 at 07:50
  • I see a couple of posts saying that just having mysqlclient will suffice, is this true? – Robert Aug 11 '17 at 07:55
1

Root cause of your problem lies here

OSError: mysql_config not found

mySQLdb is a python interface for mysql, but it is not mysql itself. You need to install mysql first.

See this link below. mysql

flamelite
  • 2,654
  • 3
  • 22
  • 42
  • I installed MySQL but I am stIll getting an error and also I am still unable to use the sudo apt-get command. – Robert Aug 11 '17 at 07:22
  • I gusess you are installing wrong package which is not compatible with python version. My guess is you are using python3 where ConfigParser(in python2) has been renamed to configparser – flamelite Aug 11 '17 at 07:28
  • When you say wrong package, what should I uninstall and install what package? – Robert Aug 11 '17 at 07:29
  • try to use the mysqlclient package which is a replacement of MySQL-python. It is a fork of MySQL-python with added support for Python 3. Use command: pip install mysqlclient – flamelite Aug 11 '17 at 07:31
  • I've done that already and I get "Requirement already satisfied: mysqlclient in ./venv/lib/python3.6/site-packages" am I able to use MySQL at this point? What command can I type to see if this package is working? – Robert Aug 11 '17 at 07:33
  • Then where are you getting that module not found error? – flamelite Aug 11 '17 at 07:36
  • 1
    @Robert I update my answer check it this is due to Python version – Kallz Aug 11 '17 at 07:40
  • @flamelite File "", line 1, in File "/private/var/folders/c4/y49xcq6j6jlcr_8yyckm75th0000gp/T/pip-build-ggizmz58/MySQL-python/setup.py", line 13, in from setup_posix import get_config File "/private/var/folders/c4/y49xcq6j6jlcr_8yyckm75th0000gp/T/pip-build-ggizmz58/MySQL-python/setup_posix.py", line 2, in from ConfigParser import SafeConfigParser ModuleNotFoundError: No module named 'ConfigParser' – Robert Aug 11 '17 at 07:47
  • flask-mysqldb is using wrong package so first uninstall that MySQL-python package – flamelite Aug 11 '17 at 07:56
1

It looks like you are confused about what you're installing. You need two things: MySQL, and a Python module that lets Flask use MySQL. You're installing the latter, but it does no good unless you actually have MySQL. MySQL is software that is totally separate from Python, so anything pip-based won't succeed in installing it. Stop searching for how to install MySQL "into Flask" and start googling things like "how to install MySQL on a Mac" and you'll be on the right track.

BrenBarn
  • 242,874
  • 37
  • 412
  • 384
  • Thanks! I think I was able to install MySQL but now I get an error ModuleNotFoundError: No module named 'ConfigParser' – Robert Aug 11 '17 at 07:14