如何使用自定义OpenSSL编译Python 3.4?

时间:2014-05-08 17:04:53

标签: python gcc openssl

我在非标准位置(/my/path为了这个例子)安装了我自己的OpenSSL,并且我希望在我针对源代码编译时使用Python 3.4进行构建。我试过的是这个(目录缩写)

CPPFLAGS="-I/my/path/include -I/my/path/include/openssl" ./configure --prefix=/my/path/

我还尝试使用C_INCLUDE_PATH和冒号分隔的路径。

然后,我运行make并获取此信息:

building '_ssl' extension
gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I./Include -I. -IInclude -I/my/path/include -I/my/path/include/openssl -I/usr/local/include -I/my/path/Python-3.4.0/Include -I/my/path/Python-3.4.0 -c /my/path/Python-3.4.0/Modules/_ssl.c -o build/temp.linux-x86_64-3.4/my/path/Python-3.4.0/Modules/_ssl.o
gcc -pthread -shared build/temp.linux-x86_64-3.4/my/path/Python-3.4.0/Modules/_ssl.o -L/my/path/lib -L/usr/local/lib -lssl -lcrypto -o build/lib.linux-x86_64-3.4/_ssl.cpython-34m.so
*** WARNING: renaming "_ssl" since importing it failed: build/lib.linux-x86_64-3.4/_ssl.cpython-34m.so: undefined symbol: SSL_get0_next_proto_negotiated

它正在寻找SSL_get0_next_proto_negotiated,但这肯定是定义的:

$ grep SSL_get0_next_proto_negotiated /my/path/include/openssl/*
/my/path/include/openssl/ssl.h:void SSL_get0_next_proto_negotiated(const SSL *s,

我不确定我做错了什么,有什么想法吗?

3 个答案:

答案 0 :(得分:39)

经过大量的拔毛后,我设法弄明白了。这是一堆环境变量...我想我可能做了一点矫枉过正,但这基本上有效:

# OpenSSL 1.0.1g
./config shared --prefix=/my/path --openssldir=/my/path/openssl
make
make install

# Python 3.4
export LDFLAGS="-L/my/path/lib/ -L/my/path/lib64/"
export LD_LIBRARY_PATH="/my/path/lib/:/my/path/lib64/"
export CPPFLAGS="-I/my/path/include -I/my/path/include/openssl"
./configure --prefix=/my/path/
make
make install

答案 1 :(得分:11)

感谢@ScottFrazer的回答。给我带来了很多麻烦。

这是我在ubuntu中使用的脚本,用最新的openssl 1.0.2g编译python。

# new openssl install
curl https://www.openssl.org/source/openssl-1.0.2g.tar.gz | tar xz && cd openssl-1.0.2g && ./config shared --prefix=/usr/local/ && make && make install

# Python install script
export LDFLAGS="-L/usr/local/lib/"
export LD_LIBRARY_PATH="/usr/local/lib/"
export CPPFLAGS="-I/usr/local/include -I/usr/local/include/openssl"
apt-get update
apt-get install build-essential checkinstall -y
apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev -y
cd /home/web/
wget https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz | tar xzf Python-2.7.11.tgz && cd Python-2.7.11 
./configure --prefix=/usr/local/ 
make altinstall

注意,安装是一个 altinstall ,这意味着它将覆盖ubuntu上的默认python。要验证安装是否成功:

/usr/local/bin/python2.7
>>> import ssl
>>> ssl.OPENSSL_VERSION
'OpenSSL 1.0.2g  1 Mar 2016'

答案 2 :(得分:4)

这就是我在3.4中解决它的方法。适用于2.7和3.4。重要的是./configure中的--with-ssl config参数:

wget https://www.python.org/ftp/python/3.4.3/Python-3.4.3.tgz
tar -xf Python-3.4.3.tgz
cd Python-3.4.3/
sudo yum install gcc
./configure --with-ssl
make && make install
# If you like to live dangerously since this will overwrite default python executable
make && make altinstall
# Safer because you access your new Python using python3.4