38

I'm struggling to install the mysql-python pip either systemwide or in a venv on Ubuntu 14.04 with MariaDB 10 installed. Also tried with MariaDB 5.5 and getting the same error. I don't have this issue with vanilla mysql-server installed.

I have the following installed via apt-get:

  • build-essential
  • python-dev
  • libmariadbclient-dev (thats the MariaDB replacement for libmysqlclient-dev)
  • python-mysqldb

Originally I thought this was an issue installing this into a venv but I've subsequently noticed mysql-python won't install systemwide either. Below are the cmds I used to install in a venv.

virtualenv venv
. venv/bin/activate
pip install mysql-python==1.2.5

In file included from _mysql.c:44:0:
/usr/include/mysql/my_config.h:439:0: warning: "HAVE_WCSCOLL" redefined [enabled by default]
 #define HAVE_WCSCOLL
^
In file included from /usr/include/python2.7/pyconfig.h:3:0,  
                 from /usr/include/python2.7/Python.h:8,
                 from _mysql.c:29:
/usr/include/x86_64-linux-gnu/python2.7/pyconfig.h:911:0: note: this is the location of the     previous definition
 #define HAVE_WCSCOLL 1

^x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions     -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/_mysql.o -L/usr/lib/x86_64-linux-gnu -lmariadbclient_r -lpthread -lz -lm -lssl -lcrypto -ldl -o build/lib.linux-x86_64-2.7/_mysql.so
/usr/bin/ld: cannot find -lssl
/usr/bin/ld: cannot find -lcrypto
collect2: error: ld returned 1 exit status

error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
Cleaning up...
Command /root/env/bin/python -c "import setuptools, tokenize;__file__='/root/env/build/mysql-    python/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-EyhO2v-record/install-record.txt --single-version-externally-managed --compile --install-headers /root/env/include/site/python2.7 failed with error code 1 in /root/env/build/mysql-python
Storing debug log for failure in /root/.pip/pip.log
Braiam
  • 1
  • 11
  • 47
  • 78
ModerationMike
  • 393
  • 1
  • 4
  • 6

4 Answers4

52

You need to have installed the development libraries of OpenSSL. It can be a libssl-dev, libssl-devel if your distribution provides separated packages for the dev libraries. Or install the complete openssl package if they don't.

(venv)➜  src  pip install mysql-python==1.2.5
Downloading/unpacking mysql-python==1.2.5
  Downloading MySQL-python-1.2.5.zip (108kB): 108kB downloaded
  Running setup.py (path:/home/braiam/src/venv/build/mysql-python/setup.py) egg_info for package mysql-python
    
Installing collected packages: mysql-python
  Running setup.py install for mysql-python
    building '_mysql' extension
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -g -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing
    In file included from _mysql.c:44:0:
    /usr/include/mysql/my_config.h:439:0: warning: "HAVE_WCSCOLL" redefined
     #define HAVE_WCSCOLL
     ^
    In file included from /usr/include/python2.7/pyconfig.h:3:0,
                     from /usr/include/python2.7/Python.h:8,
                     from _mysql.c:29:
    /usr/include/x86_64-linux-gnu/python2.7/pyconfig.h:911:0: note: this is the location of the previous definition
     #define HAVE_WCSCOLL 1
     ^
    x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wl,-z,relro -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/_mysql.o -L/usr/lib/x86_64-linux-gnu -lmariadbclient_r -lpthread -lz -lm -lssl -lcrypto -ldl -o build/lib.linux-x86_64-2.7/_mysql.so
    
Successfully installed mysql-python
Cleaning up...

But, there were two messages that you have that I didn't, namely:

/usr/bin/ld: cannot find -lssl
/usr/bin/ld: cannot find -lcrypto

Which if you did ld -lcrypto --verbose or ld -lssl --verbose wouldn't produce this results:

➜  src  ld -lcrypto --verbose | grep succeeded
attempt to open //usr/lib/x86_64-linux-gnu/libcrypto.so succeeded
ld: warning: cannot find entry symbol _start; not setting start address
➜  src  ld -lssl --verbose | grep succeeded
attempt to open //usr/lib/x86_64-linux-gnu/libssl.so succeeded
ld: warning: cannot find entry symbol _start; not setting start address

So, to fix this just make sure you have installed the libssl-dev package which provides both libraries.

Braiam
  • 1
  • 11
  • 47
  • 78
  • 8
    For CentOS 6 `yum install openssl-devel` and then `pip install MySQL-python` do the trick. – chirale Dec 03 '15 at 11:43
  • Any solution for macOS? It doesn't have `libssl-dev` package and installing `openssl` package instead (considered to be the mac equivalent of `libssl`) doesn't help at all either. – saran3h Jan 20 '20 at 06:02
  • @saran3h https://superuser.com/questions/1089390/how-to-install-libssl-dev-libffi-dev-on-mac-os – Braiam Jan 21 '20 at 01:11
  • @Braiam: Why did you change the tags for this question: https://stackoverflow.com/questions/34240703/what-are-logits-what-is-the-difference-between-softmax-and-softmax-cross-entrop ? Your work is in `javascript` and stuff like that. What do you know about `machine-learning`? – stackoverflowuser2010 Jun 25 '21 at 03:28
16

I meet the similar error on MacOS but there is no "/usr/bin/ld: cannot find -lssl" for me.

Solved with the following steps:

Step 1. Make sure you have installed openssl with homebrew.

brew install openssl

Step 2. In a terminal:

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

For Linux you can also try yum install your missing library and add them to LIBRARY_PATH.

Shaofei Cheng
  • 952
  • 9
  • 13
11

For Debian 9.x:

apt install libssl-dev

Dmitry Mottl
  • 842
  • 10
  • 17
6

For CentOS:

sudo yum install openssl-devel
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Eduard Gan
  • 515
  • 5
  • 6