OSX MySQL-python 1.2.5 error handling IndexError: string index out of range

I gave up once, but thanks to my seniors at work, my C / C ++ compilation skills have improved over the past few days, so I'll try again!

#First of all, mysql-connector by yourself-Download and install c
https://dev.mysql.com/downloads/connector/c/
#I will omit the details here,But it looks like this. tar zxvf xxxx.tar.gz; cd mysql*; mkdir build; cd build; cmake ..; make; sudo make install

# mysql_config is/usr/local/mysql/bin/Since it will be installed in, put a link appropriately
ln -s /usr/local/mysql/bin/mysql_config /usr/local/bin/

% 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/9j/12cqyk6x2s5dc22x2mnlpmmw0000gn/T/pip-build-Cf6eHO/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

#Download the zip yourself and try https://pypi.python.org/pypi/MySQL-python/1.2.5
% unzip MySQL-python-1.2.5.zip; cd MySQL-python*;
% python setup.py build
Traceback (most recent call last):
  File "setup.py", line 17, in <module>
    metadata, options = get_config()
  File "./MySQL-python-1.2.5/setup_posix.py", line 53, in get_config
    libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ]
  File "./MySQL-python-1.2.5/setup_posix.py", line 8, in dequote
    if s[0] in "\"'" and s[0] == s[-1]:
IndexError: string index out of range

#I haven't checked for Python bugs and strings here, so use the following method to Fix
if s[0] in "\"'" and s[0] == s[-1]:
To
if s and s[0] in "\"'" and s[0] == s[-1]:
change to.

#Try again
% python setup.py build
/usr/bin/clang -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -g build/temp.macosx-10.6-intel-2.7/_mysql.o -L/usr/local/mysql/lib -l -o build/lib.macosx-10.6-intel-2.7/_mysql.so
clang: error: no such file or directory: 'build/lib.macosx-10.6-intel-2.7/_mysql.so'
error: command '/usr/bin/clang' failed with exit status 1
#I thought it was this easy, but the reality is not so good!
#I checked the contents.o is made, but.Failed to create so

#Then do you compile it yourself?
clang -bundle -undefined dynamic_lookup -arch x86_64 -g build/temp.macosx-10.6-intel-2.7/_mysql.o -L/usr/local/mysql/lib -lmysqlclient -o build/lib.macosx-10.6-intel-2.7/_mysql.so 
# -lmysqlclient is the point,Python does not link on purpose, makes it discover dynamically
#No error, yes OK

#Complete by installing
% python setup.py install 
...
Processing dependencies for MySQL-python==1.2.5
Finished processing dependencies for MySQL-python==1.2.5

% python
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 12:39:47) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import _mysql
>>> import MySQLdb
>>> ^D

:)

Recommended Posts

OSX MySQL-python 1.2.5 error handling IndexError: string index out of range
Python error messages are concrete and easy to understand "ga" (IndexError: list index out of range with element [0])
Error divided by 0 Handling of ZeroDivisionError