mysql-python won't install on MacOS

1.5k Views Asked by At

So I have tried multiple ways to install mysql-python and MYSQLdb. I have tried downloading through this link: https://sourceforge.net/projects/mysql-python/ and then when I run python setup.py install I get the following errors:

Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz
Traceback (most recent call last):
  File "/Users/Jackson/Google Drive/CS520/HW/MySQL-python-1.2.4b4/distribute_setup.py", line 143, in use_setuptools
    raise ImportError
ImportError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "setup.py", line 7, in <module>
    use_setuptools()
  File "/Users/Jackson/Google Drive/CS520/HW/MySQL-python-1.2.4b4/distribute_setup.py", line 145, in use_setuptools
    return _do_download(version, download_base, to_dir, download_delay)
  File "/Users/Jackson/Google Drive/CS520/HW/MySQL-python-1.2.4b4/distribute_setup.py", line 124, in _do_download
    to_dir, download_delay)
  File "/Users/Jackson/Google Drive/CS520/HW/MySQL-python-1.2.4b4/distribute_setup.py", line 194, in download_setuptools
    src = urlopen(url)
  File "/Users/Jackson/anaconda3/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/Users/Jackson/anaconda3/lib/python3.6/urllib/request.py", line 532, in open
    response = meth(req, response)
  File "/Users/Jackson/anaconda3/lib/python3.6/urllib/request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "/Users/Jackson/anaconda3/lib/python3.6/urllib/request.py", line 570, in error
    return self._call_chain(*args)
  File "/Users/Jackson/anaconda3/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/Users/Jackson/anaconda3/lib/python3.6/urllib/request.py", line 650, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: SSL is required

I could not find a resolution that worked so I tried pip install mysql-python and then I get the following

    Traceback (most recent call last):
  File "setup.py", line 6, in <module>
    req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
NameError: name 'url' is not defined
Jacksons-MacBook-Pro:MySQL-python-1.2.4b4 Jackson$ pip install mysql-python
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/tmp/pip-build-kdgbz3qe/mysql-python/setup.py", line 13, in <module>
        from setup_posix import get_config
      File "/private/tmp/pip-build-kdgbz3qe/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/tmp/pip-build-kdgbz3qe/mysql-python/

When I look this problem up I tried running:

pip install --upgrade setuptools
pip install ez_setup
easy_install -U setuptools

With no problems, but then when I tried rerunning the command pip install mysql-python I get the same error as before. I tried downloading the mysqlclient and the mysql/python connector and nothing is working. I just want a fix for trying to install mysql-python, mysqlclient, MYSQLdb, mysql/python connector or anything that will actually work. I already have mysql installed and running as well as Sequel Pro.

2

There are 2 best solutions below

1
On
0
On

I could solve the issue by running the combination of @Devstr an @jsteele. I realized that the python module to connect from python to mysql is not mysql but ```mysql-connector``.

Follow these steps:

brew cask install mysql-connector-python
pip search mysql-connector | grep --color mysql-connector-python
pip install mysql-connector-python-rf

then in python:

import mysql.connector
...

found some useful info: What's the difference between MySQLdb, mysqlclient and MySQL connector/Python?