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新手。)
4 个解决方案
#1
27
-
At a shell prompt (in a terminal), run
在shell提示符(终端)处运行
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.
这将获取构建python所需的所有库。
-
Then download the source code for python and decompress it into a directory.
然后下载python的源代码并将其解压缩到一个目录中。
-
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
If you hit snags on the way, ask back here and I'll try to offer some guidance.
如果你在路上遇到了障碍,请回到这里,我会试着提供一些指导。
#2
7
The best way to build "hot" very recent python (from github) is as follows:
构建“hot”最近的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-$(uname -r) 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.7.0a0 (heads/master:60a6632a3d, Aug 5 2017)
.
用这个我构建了Python 3.7.0a0 (head /master:60a6632a3d, 2017年8月5日)。
#3
4
You may try using pyenv. I haven't tried it yet. But looking at the sources, it seems very mature to accomplish an installation of any CPython-interpreter on any *ix-system.
您可以尝试使用pyenv。我还没试过。但是从源代码来看,在任何x系统上完成任何cpython -解释器的安装似乎都非常成熟。
#4
2
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是最可行的解决方案。
#1
27
-
At a shell prompt (in a terminal), run
在shell提示符(终端)处运行
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.
这将获取构建python所需的所有库。
-
Then download the source code for python and decompress it into a directory.
然后下载python的源代码并将其解压缩到一个目录中。
-
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
If you hit snags on the way, ask back here and I'll try to offer some guidance.
如果你在路上遇到了障碍,请回到这里,我会试着提供一些指导。
#2
7
The best way to build "hot" very recent python (from github) is as follows:
构建“hot”最近的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-$(uname -r) 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.7.0a0 (heads/master:60a6632a3d, Aug 5 2017)
.
用这个我构建了Python 3.7.0a0 (head /master:60a6632a3d, 2017年8月5日)。
#3
4
You may try using pyenv. I haven't tried it yet. But looking at the sources, it seems very mature to accomplish an installation of any CPython-interpreter on any *ix-system.
您可以尝试使用pyenv。我还没试过。但是从源代码来看,在任何x系统上完成任何cpython -解释器的安装似乎都非常成熟。
#4
2
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是最可行的解决方案。