Python编译错误:构建模块_ssl和_hashlib失败。

16

我将Python 2.7.13作为备用安装版本,通过在我的RHEL4机器上安装源代码来实现

wget --no-check-certificate https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tar.xz
tar -xvzf Python2.7.13.tar.xz
cd Python2.7.13
./configure --with-ensurepip=install
make
make test
make altinstall

为了不覆盖其他用途所需的默认Python,我需要进行翻译。Python 2.7.13 可以成功安装,但是缺少项目所需的几个必要模块。 最初,在此部分中 _ssl 和 _haslib 模块将出现错误。
Python build finished, but the necessary bits to build these modules were not found:
_bsddb             _sqlite3           _tkinter
bsddb185           dbm                dl
gdbm               imageop            sunaudiodev

To find the necessary bits, look in setup.py in detect_modules() for the module's name.

我安装了openssl并确保它们在Python默认查找位置上,所以现在我有了必要的部件,但是最后出现了以下消息:
Failed to build these modules:
_hashlib           _ssl

以下是未压缩的Python软件包中 python2.7 setup.py build 的完整输出。我已经在谷歌和其他地方搜索过,但到目前为止都没有找到任何有用的信息。
running build
running build_ext
INFO: Can't locate Tcl/Tk libs and/or headers
building '_ssl' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/ssl/include -I. -IInclude -I./Include -I/usr/local/include -I/usr/local/include/python2.7 -c /Python/Modules/_ssl.c -o build/temp.linux-x86_64-2.7/Python/Modules/_ssl.o
/Python/Modules/_ssl.c:57: warning: ignoring #pragma GCC diagnostic
/Python/Modules/_ssl.c: In function ‘_setup_ssl_threads’:
/Python/Modules/_ssl.c:4012: warning: comparison is always false due to limited range of data type
gcc -pthread -shared build/temp.linux-x86_64-2.7/Python/Modules/_ssl.o -L/usr/local/ssl/lib -L/usr/local/lib -lssl -lcrypto -o build/lib.linux-x86_64-2.7/_ssl.so
/usr/bin/ld: /usr/local/ssl/lib/libssl.a(s3_meth.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
/usr/local/ssl/lib/libssl.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
building '_hashlib' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/ssl/include -I. -IInclude -I./Include -I/usr/local/include -I/usr/local/include/python2.7 -c /Python/Modules/_hashopenssl.c -o build/temp.linux-x86_64-2.7/Python/Modules/_hashopenssl.o
gcc -pthread -shared build/temp.linux-x86_64-2.7/Python/Modules/_hashopenssl.o -L/usr/local/ssl/lib -L/usr/local/lib -lssl -lcrypto -o build/lib.linux-x86_64-2.7/_hashlib.so
/usr/bin/ld: /usr/local/ssl/lib/libcrypto.a(o_names.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
/usr/local/ssl/lib/libcrypto.a: could not read symbols: Bad value
collect2: ld returned 1 exit status

Python build finished, but the necessary bits to build these modules were not found:
_bsddb             _sqlite3           _tkinter
bsddb185           dbm                dl
gdbm               imageop            sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.


Failed to build these modules:
_hashlib           _ssl

 running build_scripts

当我尝试使用安装在我的Python 2.7.13中的pip时,出现了SSL错误,因此我一直从源代码安装所有软件包和其他模块,如cx_Oracle和CherryPy。
pip2.7 install cffi
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting cffi
  Could not fetch URL https://pypi.python.org/simple/cffi/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
  Could not find a version that satisfies the requirement cffi (from versions: )
No matching distribution found for cffi

我也尝试使用手动方式添加ssl模块:

wget --no-check-certificate https://pypi.python.org/packages/83/21/f469c9923235f8c36d5fd5334ed11e2681abad7e0032c5aba964dcaf9bbb/ssl-1.16.tar.gz#md5=fb12d335d56f3c8c7c1fefc1c06c4bfb
tar -xvzf ssl-1.16.tar.gz
cd ssl-1.16
python2.7 setup.py build

但是我遇到了一个错误,它不能在Python 2.6之后的版本中使用

Traceback (most recent call last):
  File "setup.py", line 12, in <module>
    + "or earlier.")
ValueError: This extension should not be used with Python 2.6 or later (already built in), and has not been tested with Python 2.3.4 or earlier.

编辑

我正在寻找解决方案,经过检查setup.py build的输出后,发现有人遇到了类似的问题,似乎与openssl相关,链接在这里。因此,我重新构建了我的openssl。

./config enable-shared
make
make test
make install

现在我遇到了一个稍微不同的关于ssl模块的错误,我是不是越来越搞砸我的环境了?

python2.7 setup.py build
running build
running build_ext
INFO: Can't locate Tcl/Tk libs and/or headers
building '_ssl' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/ssl/include -I. -IInclude -I./Include -I/usr/local/include -I/usr/local/include/python2.7 -c /Python/Modules/_ssl.c -o build/temp.linux-x86_64-2.7/Python/Modules/_ssl.o
/Python/Modules/_ssl.c:57: warning: ignoring #pragma GCC diagnostic
/Python/Modules/_ssl.c: In function ‘_setup_ssl_threads’:
/Python/Modules/_ssl.c:4012: warning: comparison is always false due to limited range of data type
gcc -pthread -shared build/temp.linux-x86_64-2.7/Python/Modules/_ssl.o -L/usr/local/ssl/lib -L/usr/local/lib -lssl -lcrypto -o build/lib.linux-x86_64-2.7/_ssl.so
*** WARNING: renaming "_ssl" since importing it failed: libssl.so.1.0.0: cannot open shared object file: No such file or directory
building '_hashlib' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/ssl/include -I. -IInclude -I./Include -I/usr/local/include -I/usr/local/include/python2.7 -c /Python/Modules/_hashopenssl.c -o build/temp.linux-x86_64-2.7/Python/Modules/_hashopenssl.o
gcc -pthread -shared build/temp.linux-x86_64-2.7/Python/Modules/_hashopenssl.o -L/usr/local/ssl/lib -L/usr/local/lib -lssl -lcrypto -o build/lib.linux-x86_64-2.7/_hashlib.so
*** WARNING: renaming "_hashlib" since importing it failed: libssl.so.1.0.0: cannot open shared object file: No such file or directory

Python build finished, but the necessary bits to build these modules were not found:
_bsddb             _sqlite3           _tkinter
bsddb185           dbm                dl
gdbm               imageop            sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.


Failed to build these modules:
_hashlib           _ssl

running build_scripts

输出中的新警告信息:***警告:由于导入失败,重命名“_ssl”:libssl.so.1.0.0:无法打开共享对象文件:没有那个文件或目录表示该文件不存在,但我在 /usr/local/ssl/lib/ 中看到了它作为 libssl.so.1.0.0 并且可以通过搜索找到。

find / -name libssl.so.1.0.0
/usr/local/ssl/lib/libssl.so.1.0.0
/tmp/openssl-1.0.2l/libssl.so.1.0.0
1个回答

12

嗯,我不知道是否应该感到愚蠢。因为我对linux命令行界面还很陌生,所以可能会忽略一些常见的操作。但是,在https://dev59.com/13RB5IYBdhLWcg3w4bAo#28460293中,我能够通过几个简单的步骤解决了构建_hashlib和_ssl模块的错误,这得益于amo的回答。

我首先尝试使用ldconfig,但这并没有解决我的问题,所以我只是查看了我的LD_LIBRARY_PATH中有些什么内容。

echo $LD_LIBRARY_PATH

然后得到了这些位置,但不包括 libssl.so.1.0.0 文件所在的位置。

/usr/lib/oracle/11.2/client64/lib:/usr/lib/oracle/11.2/client/lib

然后我按照之前在这篇博客文章中详细描述的步骤,安装Oracle即时客户端和cx_Oracle模块:https://ubuntugeeknerd.blogspot.com/2013/08/how-to-install-oxoracle-in-rhel-64-bit.html

我用于ssl模块的那些步骤如下:

export LD_LIBRARY_PATH=/usr/local/ssl/lib/:$LD_LIBRARY_PATH >> ~/.bashrc
echo $LD_LIBRARY_PATH
/usr/local/ssl/lib/:/usr/lib/oracle/11.2/client64/lib:/usr/lib/oracle/11.2/client/lib

接下来,我执行了python2.7 setup.py clean,然后是python2.7 setup.py build,最后是python2.7 setup.py install。输出结果没有任何构建失败的提示,除了那些我没有必要(也没打算)构建所需部件的提示。

现在,当我打开Python并成功导入该模块时,我可以确认SSL模块已经存在。

Python 2.7.13 (default, Jun 26 2017, 15:21:33)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>>

希望这对遇到类似问题的人有所帮助。


FYI,cx_Oracle 6(目前处于RC 1发布状态)具有Wheels,因此任何旧的安装说明可能已过时。此外,如果从源代码构建它,则不再需要Oracle头文件。 - Christopher Jones
在我的情况下,构建 OpenSSL 时,我需要使用“shared”选项(-fPIC)进行配置。 - João Paulo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接