1

MacOS | Python 2.7

I want to use MySQLdb. When I run

pip install MySQL-python

The result is

JourneydeMacBook-Pro:~ JourneyWoo$ 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/var/folders/g9/y4rms8zx6yvjjn1m1w6w0000gn/T/pip-build-JFpAwP/MySQL-python/setup.py", line 17, in <module>
    metadata, options = get_config()
      File "setup_posix.py", line 53, in get_config
        libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ]
      File "setup_posix.py", line 8, in dequote
        if s[0] in "\"'" and s[0] == s[-1]:
    IndexError: string index out of range

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/g9/y4rms8zx6yvjjn1m1w6w0000gn/T/pip-build-JFpAwP/MySQL-python/

I think my pip got a problem, so I run

pip install --upgrade setuptools
pip install ez_setup
pip install unroll

They all work well, but when I try again

pip install MySQL-python

It still has the problem.

I did not get the answer which could solve my question and problem from Google Search, really thank you if you could help me with this.

7
  • Try installing in a virtual environment. Commented Jun 3, 2017 at 11:25
  • I still cannot solve this question, so I have to give up mysqldb and use pymysql, which is installed by "conda install pymysql" Commented Jun 4, 2017 at 15:39
  • It really comes down how you installed MYSQL on your local MAC. Did you use BREW to install it? And if so, did you upgrade recently? I ran into similar issue when I ran brew update. If all of these are true let me know and I can try and help clean that up. Commented Jul 19, 2017 at 22:43
  • @JohnnyGasyna yes, but I had updated it and this method did not work... Commented Jul 24, 2017 at 17:02
  • 1
    Also you can try clearing pip's cache, described here: stackoverflow.com/questions/9510474/removing-pips-cache Commented Jul 25, 2017 at 18:19

2 Answers 2

1

sudo apt-get install python-dev default-libmysqlclient-dev # Debian / Ubuntu running this solved my problem

Sign up to request clarification or add additional context in comments.

Comments

0

For linux users

First install python3-dev by;

laptop$sudo apt-get install python3-dev # debian / Ubuntu
laptop$sudo yum install python3-devel # Red Hat / CentOS
laptop$sudo apt-get install mysqlclient

If you've previous installation in virtual environment uninstall it, it will also remove MYSQLdb which in my case was the source of all the problem. Then re-install;

   (venv)laptop:~/Desktop/app/$ pip uninstall mysqlclient
    Uninstalling mysqlclient-1.3.13:
     Would remove:
    /usr/local/lib/python3.7/site-packages/MySQLdb/*
    /usr/local/lib/python3.7/site-packages/_mysql.cpython-37m-x86_64-linux-gnu.so
    /usr/local/lib/python3.7/site-packages/_mysql_exceptions.py
    /usr/local/lib/python3.7/site-packages/mysqlclient-1.3.13-py3.7.egg-info   
   Proceed (y/n)? y
   (venv)laptop:~/Desktop/app/$ pip install mysqlclient

More details here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.