Install python3 in linux

Installation environment: CentOS 7 
python version: python3
At present, CentOS7 comes with python2, but some articles on the Internet say that python2 is only supported until 2020. Just use python3, after all, python3 is relatively stable, and it will be simpler than python2.
The full text of this article uses yum installation, because it is too convenient, haha.
Note: there is no need to manage the python2 that comes with the system.

1. Install python3.6.1
  • wget --no-check-certificate https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz 
  • tar -zxvf Python-3.6.1.tgz            
  • cd Python-3.6.1               
  • ./configure --prefix=/home/python3 --enable-shared        //Specify the installation directory --enable-shared is compiled into a static library
  • make install 
  • ln -s /home/python3/bin/python3 /usr/bin/python3 //add soft link

* Add a soft link, which means to create a convenient alias without changing the original directory/file. The amount is similar to the desktop icon

At this time, if you run the python3 command, an error will be reported, and the .so file is missing. We need to do the following:

cp -R /home/python3/lib/* /usr/lib64/

2. Install pip and setuptools
In order to install the third-party library more conveniently, using the pip command, we need to install it accordingly.
1. Before installing pip, you need to install setuptools in advance
  • wget --no-check-certificate  https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
  • tar -zxvf setuptools-19.6.tar.gz
  • cd setuptools-19.6
  • python3 setup.py build
  • python3 setup.py install
2. Install pip
  • wget --no-check-certificate  https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb
  • tar -zxvf pip-8.0.2.tar.gz
  • cd pip-8.0.2
  • python3 setup.py build
  • python3 setup.py install           
3. Test

Enter python3 in the terminal, print hello, python3 test is successful




Guess you like

Origin blog.csdn.net/u010994966/article/details/79262229