Python安裝-在Linux系統中使用編譯進行安裝python
你能夠使用Ubuntu自帶的Python3,不過你不能自由的控制版本,還要單獨安裝pip3,若是你想升級pip3,還會出現一些讓人不愉快的使用問題。而在CentOS系統中,默認只有Python2,經過yum安裝Python3,也一樣面臨版本落後以及pip3的問題。若是不本身編譯安裝,還有什麼別的方法來一直保持使用最新的版本呢?!除非你用Win系統。sql
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.ubuntu
在CentOS中安裝Python3須要的依賴庫centos
Install the dependency libraries required by Python3 in CentOSless
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須要的依賴庫curl
Install the dependency libraries required by Python3 in Ubuntuui
$ sudo apt install libreadline-gplv2-devlibncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libbz2-devzlib1g-dev libffi-dev liblzma-dev
安裝GCCurl
Install GCCspa
CentOS的minimal版本,以及Ubuntu,都沒有預裝gcc,若是你用的是這兩個版本,須要確保系統有gcc編譯器能夠使用。安裝和查看gcc的方法:code
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