Python Build Error: failed to build modules _ssl and _hashlib
Python Build Error: failed to build modules _ssl and _hashlib
我正在添加 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
的完整输出。我一直在搜索 google 和我能找到的任何地方,但到目前为止我都没有成功
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 past 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 here 有关
所以我用
重建了我的 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
输出 *** WARNING: renaming "_ssl" since importing it failed: libssl.so.1.0.0: cannot open shared object file: No such file or directory
中的新警告消息表明该文件不存在,但我在 /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
好吧,我不知道是否觉得自己很愚蠢,这只是我完全忽略的一件常见事情,因为我对 linux CLI 还很陌生。但是,我能够通过 amo 的响应中的几个简单步骤解决 _hashlib 和 _ssl 模块的构建错误。
我首先尝试了 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 模块时所做的步骤进行操作,这些步骤很容易放在这个博客 post 上: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
。输出没有 return 除了我没有必要的位(并且无论如何也不打算构建)之外的任何构建失败。
我可以在打开 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
>>>
希望这对 运行 遇到类似问题的人有用
我正在添加 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
的完整输出。我一直在搜索 google 和我能找到的任何地方,但到目前为止我都没有成功
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 past 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 here 有关
所以我用
./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
输出 *** WARNING: renaming "_ssl" since importing it failed: libssl.so.1.0.0: cannot open shared object file: No such file or directory
中的新警告消息表明该文件不存在,但我在 /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
好吧,我不知道是否觉得自己很愚蠢,这只是我完全忽略的一件常见事情,因为我对 linux CLI 还很陌生。但是,我能够通过 amo 的响应中的几个简单步骤解决 _hashlib 和 _ssl 模块的构建错误。
我首先尝试了 ldconfig
,但这并没有解决我的问题,所以我只是用
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 模块时所做的步骤进行操作,这些步骤很容易放在这个博客 post 上: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
。输出没有 return 除了我没有必要的位(并且无论如何也不打算构建)之外的任何构建失败。
我可以在打开 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
>>>
希望这对 运行 遇到类似问题的人有用