关于linux:Python安装在Linux系统中使用编译进行安装

30次阅读

共计 2359 个字符,预计需要花费 6 分钟才能阅读完成。

Python 装置 - 在 Linux 零碎中应用编译进行装置

你能够应用 Ubuntu 自带的 Python3,不过你不能自在的管制版本,还要独自装置 pip3,如果你想降级 pip3,还会呈现一些让人不欢快的应用问题。而在 CentOS 零碎中,默认只有 Python2,通过 yum 装置 Python3,也同样面临版本落后以及 pip3 的问题。如果不本人编译装置,还有什么别的办法来始终放弃应用最新的版本呢?!除非你用 Win 零碎。

You can use the Python3 that comes with Ubuntu, but you can’t control the version freely. You have to install pip3 separately. If you want to upgrade pip3, there will be some unpleasant usage problems. In the CentOS system, there is only Python2 by default. Installing Python3 through yum also faces the problems of backward version and pip3. If you don’t compile and install it yourself, what other methods are there to keep using the latest version? ! Unless you use Win system.

在 CentOS 中装置 Python3 须要的依赖库

Install the dependency libraries required by Python3 in CentOS

sudo yum install zlib-devel bzip2-developenssl-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-develexpat-devel gdbm-devel xz-devel db4-devel libpcap-devel make

在 Ubuntu 中装置 Python3 须要的依赖库

Install the dependency libraries required by Python3 in Ubuntu

$ sudo apt install libreadline-gplv2-devlibncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libbz2-devzlib1g-dev libffi-dev liblzma-dev

装置 GCC

Install GCC

CentOS 的 minimal 版本,以及 Ubuntu,都没有预装 gcc,如果你用的是这两个版本,须要确保零碎有 gcc 编译器能够应用。装置和查看 gcc 的办法:

The minimal version of CentOS and Ubuntu do not have gcc pre-installed. If you are using these two versions, you need to make sure that the system has a gcc compiler that can be used. How to install and view gcc:

$ sudo yum install gcc  # install gcc in centos
$ sudo apt install gcc  # install gcc in ubuntu
$ which gcc # check if gcc is there
$ gcc --version  # check gcc version

下载 Python3 源码并解压

Download the Python3 source code and unzip it

Python3 的官网源码下载页面是:https://www.python.org/downlo…

The official source code download page of Python3 is:

https://www.python.org/downlo…

应用 curl 或 wget 下载,而后解压:

Use curl or wget to download, and then unzip:

Wget https://www.python.org/ftp/python/3.9.2/Python-3.9.2.tgz
tar xvf Python-3.9.2.tgz

执行 configure

Execute configure

进入上一步的解压目录,而后执行 configure:

Enter the unzipped directory of the previous step, and then execute configure:

$ cd Python-3.7.3
$ ./configure --prefix=/usr/local/python-3.9.2

make 和 install

make and install

最初,咱们执行 make 和 install 的指令。

Finally, we execute the make and install instructions.

$ make && sudo make install

make install 前要有 sudo,因为咱们在 configure 的时候,指定的装置门路为零碎门路,不是用户的 /home/user 门路。

There must be sudo before make install, because when we configure, the specified installation path is the system path, not the user’s /home/user path.

ln -s /usr/local/python-3.9.2/bin/python3.9/usr/bin/python3
ln -s /usr/local/python-3.9.2/bin/pip3.9/usr/bin/pip3

正文完
 0