Linux 我将如何从 Ubuntu 上的源代码自己构建 python?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8097161/
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 would I build python myself from source code on Ubuntu?
提问by Brian Schmitz
Ubuntu comes with Python 2.7.2+ pre-installed. (I also downloaded the python dev packages.) Because of another issue I'm having (Explained in extreme depth in How do I replace/update the version of the expat library used by Apache?), Graham Dumpleton told me my distro had explicitly built Python in a way to use an external pyexpat implementation, so causing my issue. He also said I could build Python myself from source code to resolve the issue. How would I do this on Ubuntu? (Keep in mind I'm new to Linux.)
Ubuntu 预装了 Python 2.7.2+。(我还下载了 python 开发包。)由于我遇到的另一个问题(在如何替换/更新 Apache 使用的 expat 库的版本中进行了极其深入的解释?),Graham Dumpleton 告诉我我的发行版已经明确以使用外部 pyexpat 实现的方式构建 Python,因此导致了我的问题。他还说我可以从源代码自己构建 Python 来解决这个问题。我将如何在 Ubuntu 上执行此操作?(请记住,我是 Linux 新手。)
采纳答案by Noufal Ibrahim
At a shell prompt (in a terminal), run
sudo apt-get install build-essential
This will fetch all the common packages you need to build anything (e.g. the compiler etc.).
Then run
sudo apt-get build-dep python2.7
This will fetch all the libraries you need to build python.
Then download the source code for python and decompress it into a directory.
go there and run
./configure --prefix=/path/where/you/want/python/installed
Then
make
and thenmake install
to get it built and installed:make && make install
在 shell 提示符下(在终端中),运行
sudo apt-get install build-essential
这将获取构建任何东西所需的所有公共包(例如编译器等)。
然后运行
sudo apt-get build-dep python2.7
这将获取构建 python 所需的所有库。
然后下载python的源代码并解压到一个目录中。
去那里跑
./configure --prefix=/path/where/you/want/python/installed
然后
make
然后make install
构建和安装它:make && make install
If you hit snags on the way, ask back here and I'll try to offer some guidance.
如果您在途中遇到障碍,请在这里询问,我会尽力提供一些指导。
回答by pyroscope
The superior solution to building Python yourself is pythonbrew, which automates the process and also allows you to not only install several different versions, but also easily select between them.
自己构建 Python 的最佳解决方案是pythonbrew,它可以自动化该过程,并且不仅允许您安装多个不同的版本,还可以轻松地在它们之间进行选择。
In 2016, pyenv and PyRun are the most viable solutions.
2016 年,pyenv 和 PyRun 是最可行的解决方案。
回答by funky-future
回答by Suman Khanal
The best way to build "hot" very recent python (from github) is as follows:
构建“热门”最近的python(来自github)的最佳方法如下:
sudo apt-get update \
&& sudo apt-get install -y build-essential git libexpat1-dev libssl-dev zlib1g-dev \
libncurses5-dev libbz2-dev liblzma-dev \
libsqlite3-dev libffi-dev tcl-dev linux-headers-generic libgdbm-dev \
libreadline-dev tk tk-dev
git clone https://github.com/python/cpython.git
cd cpython && ./configure --prefix=/usr \
--enable-loadable-sqlite-extensions \
--enable-shared \
--with-lto \
--enable-optimizations \
--with-system-expat \
--with-system-ffi \
--enable-ipv6 --with-threads --with-pydebug --disable-rpath \
&& make \
&& sudo make install
It builds the very recent python from the sources on github.
它从 github 上的源代码构建了最新的 python。
With this I have built Python 3.8.0a0 (heads/master:077059e0f0, Aug 10 2018, 21:36:32)
.
有了这个,我已经建立了Python 3.8.0a0 (heads/master:077059e0f0, Aug 10 2018, 21:36:32)
.
回答by mb47
You can use checkinstall to install from source code instead of make install.
您可以使用 checkinstall 从源代码安装而不是 make install。
Once you download the source code, navigate to the home folder and use below commands
下载源代码后,导航到主文件夹并使用以下命令
./configure
make
sudo checkinstall
This creates a debian / RPM package and then installs it. Checkinstall keeps a tab of all the files modifications and dependencies and makes the whole uninstalling process easier. Since you have a .deb package, it's much easier to install on many systems and handle with a package manager.
这将创建一个 debian / RPM 包,然后安装它。Checkinstall 保留所有文件修改和依赖项的选项卡,并使整个卸载过程更容易。由于您有一个 .deb 包,因此在许多系统上安装并使用包管理器处理要容易得多。