忽略surepip失败pip在Ubuntu 18.04中要求ssl / tls错误
问题内容:
获取 忽略ensurepip失败PIP需要SSL / TLS 尝试安装Python和PIP在当错误 的Ubuntu 18.04
尝试运行sudo make install
会出现上述错误。
# Download Python
curl -O https://www.python.org/ftp/python/3.4.2/Python-3.4.2.tgz
tar -xzvvf Python-3.4.2.tgz
cd Python-3.4.2
export CFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib -I/usr/local/opt/zlib/include -L/usr/local/opt/zlib/lib"
# Required Dependencies
sudo apt-get install libssl-dev openssl
sudo apt-get install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libpq-dev zlib1g-dev
# Prepare to install Python
./configure
make -j4
sudo make install
问题答案:
这是由于Debian 9
使用OpenSSL 1.1.0
,然而,OpenSSL 1.1.0
在SSL模块,支持只加入到了Python
2.7.13
,3.5.3
并且3.6+
因此,它使那些版本下的蟒蛇不能正确链接到ssl
库。问题https://github.com/pyenv/pyenv/issues/945
因此,在编译它们时必须手动添加这些库。
我的建议
由于您的系统已经使用默认的python进行编译,因此无意中将不同版本的python编译为global
可执行文件可能会导致许多隐藏的问题,尤其是在系统默认python后面使用的某些命令。
那么,为什么不使用pyenv
来控制那些python版本呢?pyenv
就像是一个Python版本的控制程序,它使用shims
,通过一个名为老调重弹的过程,pyenv
维持shims
在该目录中跨的每一个安装的版本每个Python命令匹配python
,pip
等。有关更多文档,请阅读:https
:
//github.com/pyenv/pyenv。要进行安装pyenv
,请遵循提供的参考。
解
经过许多小时的努力,我终于找到了一种解决方案,可以完美地解决这些版本的python冲突问题,将以下脚本复制并粘贴到新文件中,并使其可执行,然后可以编译并安装这些python。如果您想以其他方式安装它们,例如,不使用pyenv
,请更改最后第二行命令以适合您的需求。
#!/bin/bash -e
# Note: it is a script to solve Ubuntu 18.04 LTS
# different version of pythons compiling
# header confliction problems
#
# The idea is got from @JustAnotherArivist
# From URL: https://github.com/pyenv/pyenv/issues/945
#
# The script used in here is with slightly modifications
# to fit many different SSL header versions
# First under your home directory make OpenSSL library
# and extract useful package
mkdir ~/libssl1.0-dev
cd ~/libssl1.0-dev
apt-get download libssl1.0-dev
ar x libssl1.0-dev* data.tar.xz
tar -xf data.tar.xz --strip-components=2
# Second, specifically get your current system's SSL headers
# and make symbolic-links
libcrypto=$(ls /usr/lib/x86_64-linux-gnu/ | grep libcrypto.so......)
libssl=$(ls /usr/lib/x86_64-linux-gnu/ | grep libssl.so......)
ln -s /usr/lib/x86_64-linux-gnu/${libcrypto} ~/libssl1.0-dev/lib/x86_64-linux-gnu
ln -s /usr/lib/x86_64-linux-gnu/${libssl} ~/libssl1.0-dev/lib/x86_64-linux-gnu
# Set your CFLAGS LDFLAGS compile options
# And use pyenv install the python version <3.4.5 or <3.5.3
# Note: it is a one line command
# Please change the version of python that you want to compile
CFLAGS="-I${HOME}/libssl1.0-dev/include -I${HOME}/libssl1.0-dev/include/x86_64-linux-gnu" \
LDFLAGS="-L${HOME}/libssl1.0-dev/lib/x86_64-linux-gnu" \
pyenv install 3.4.2
# Remove tempor libssl1.0-dev direcotory
rm -rf ~/libssl1.0-dev