【问题标题】:"cannot find -lssl; cannot find -lcrypto" when installing mysql-python?安装mysql-python时“找不到-lssl;找不到-lcrypto”?
【发布时间】:2014-11-16 17:46:25
【问题描述】:

我正在努力在安装了 MariaDB 10 的 Ubuntu 14.04 上安装 mysql-python pip 或者在系统范围内或在 venv 中。还尝试使用 MariaDB 5.5 并得到相同的错误。我安装了 vanilla mysql-server 没有这个问题。

我通过 apt-get 安装了以下内容:

  • 构建必不可少
  • python-dev
  • libmariadbclient-dev(这是 libmysqlclient-dev 的 MariaDB 替代品)
  • python-mysqldb

最初我认为这是将其安装到 venv 中的问题,但后来我注意到 mysql-python 也不会在系统范围内安装。以下是我用来安装在 venv 中的 cmd。

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

【问题讨论】:

    标签: pip virtualenv mysql-python


    【解决方案1】:

    您需要安装 OpenSSL 的开发库。如果您的发行版为开发库提供单独的包,它可以是 libssl-dev、libssl-devel。或者如果没有安装完整的 openssl 包。

    (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...
    

    但是,你有两条我没有的信息,即:

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

    如果你使用ld -lcrypto --verboseld -lssl --verbose 不会产生这样的结果:

    ➜  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
    

    因此,要解决此问题,只需确保您已安装提供这两个库的 libssl-dev 包。

    【讨论】:

    • 对于 CentOS 6 yum install openssl-devel 然后 pip install MySQL-python 就可以了。
    • macOS 有什么解决方案吗?它没有libssl-dev 包,而是安装openssl 包(被认为是libssl 的mac 等效项)也根本没有帮助。
    • @Braiam:你为什么要更改这个问题的标签:stackoverflow.com/questions/34240703/…?你的工作在javascript 之类的。你对machine-learning了解多少?
    【解决方案2】:

    我在 MacOS 上遇到了类似的错误,但我没有“/usr/bin/ld: cannot find -lssl”。

    通过以下步骤解决:

    第 1 步。确保您已使用 homebrew 安装了 openssl。

    brew install openssl
    

    第 2 步。在终端中:

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

    对于 Linux,您还可以尝试 yum install 您缺少的库并将它们添加到 LIBRARY_PATH。

    【讨论】:

      【解决方案3】:

      对于 Debian 9.x:

      apt install libssl-dev

      【讨论】:

        【解决方案4】:

        对于 CentOS:

        sudo yum install openssl-devel
        

        【讨论】:

          猜你喜欢
          • 2017-03-28
          • 2015-02-27
          • 2020-04-21
          • 2014-12-04
          • 2019-11-24
          • 1970-01-01
          • 2020-09-12
          • 2019-01-13
          相关资源
          最近更新 更多