如何使用自定义 OpenSSL 编译 Python 3.4?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23548188/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I compile Python 3.4 with custom OpenSSL?
提问by Scott Frazer
I have my own OpenSSL installation in a non-standard location (/my/path
for the sake of this example) and I want Python 3.4 to build against that when I compile it against source. What I tried is this (directories abbreviated)
我在非标准位置安装了自己的 OpenSSL(/my/path
就本示例而言),我希望 Python 3.4 在我针对源代码编译时针对它进行构建。我试过的是这个(目录缩写)
CPPFLAGS="-I/my/path/include -I/my/path/include/openssl" ./configure --prefix=/my/path/
I also tried with C_INCLUDE_PATH
and colon separated paths.
我也试过用C_INCLUDE_PATH
和冒号分隔的路径。
Then, I run make
and get this:
然后,我运行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
It's looking for SSL_get0_next_proto_negotiated
, but that's most certainly defined:
它正在寻找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,
I'm not sure what I'm doing wrong, any ideas?
我不确定我做错了什么,有什么想法吗?
采纳答案by Scott Frazer
I managed to figure it out after a lot of hair-pulling. It was a bunch of environment variables... I think I might have done a little overkill, but this basically worked:
经过大量的拔毛后,我设法弄清楚了。这是一堆环境变量......我想我可能做得有点矫枉过正,但这基本上有效:
# 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
回答by dex
This is how I solved it in 3.4. It is applicable for 2.7 and 3.4. The important is --with-ssl config argument in the ./configure:
这就是我在 3.4 中解决的方法。它适用于 2.7 和 3.4。重要的是 ./configure 中的 --with-ssl 配置参数:
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
回答by Hassek
Thanks @ScottFrazer for his answer. Saved me a lot of troubles.
感谢@ScottFrazer 的回答。为我省去了很多麻烦。
Here is a script I used in ubuntu to compile python with the latest openssl 1.0.2g
.
这是我在 ubuntu 中使用的一个脚本,用于使用最新的openssl 1.0.2g
.
# 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
Notice, the install is an altinstallwhich means it will notoverride the default python on ubuntu. To verify the installation was successful:
请注意,安装是altinstall,这意味着它不会覆盖 ubuntu 上的默认 python。验证安装是否成功:
/usr/local/bin/python2.7
>>> import ssl
>>> ssl.OPENSSL_VERSION
'OpenSSL 1.0.2g 1 Mar 2016'