preface
Start to write my own Python learning notes here.
Linux installation Python3
Linux systems all come with Python2, and since Python2 has stopped maintaining updates, they are now using Python3.
Python3 needs to be installed on a Linux system. So record here, go to the lavatory oneself later view.
Check whether GCC is installed
It’s usually installed, but let’s verify.
If no, run the yum -y install GCC command to install GCC
Installing dependency packages
Just execute the following command:
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
Download the source code for Python3
Url :Python source code url
To find the version you need, execute the following command:
Wget HTTP: / / https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz
Note: yum install -y wget may not be installed.
Compile and install Python3
1) After downloading, unpack: tar -zxf python-3.7.5.tgz
2) Then, go to the decompressed directory: CD python-3.7.5
3) Create Python3 installation path before compiling and installing: mkdir /usr/local/python3
/configure –prefix=/usr/local/python3
5) Compile and install: make & make install
Creating a Soft connection
Equivalent to environment configuration, python3 and PIp3 can be called directly
Ln -s/usr/local/python3 / bin/python3.7 / usr/bin/python3
Ln -s/usr/local/python3 / bin/pip3.7 / usr/bin/pip3
Configuration PIP source
Because the domestic network is often unstable, using the default PIP source provided by Python can sometimes take a long time to install packages.
Therefore, the PIP source can be changed to the domestic one. Douban is used here.
1) Create a. PIP directory for the current user: mkdir ~/.pip
2) Create the PIP configuration file vi ~/.pip/pip.conf
3) Add the following content to pip.conf:
[global]
index-url = https://pypi.douban.com/simple
[install]
trusted-host=pypi.douban.com
Copy the code
Automatic installation script
#! /bin/bash
gcc --version > /dev/null 2>&1
if[$?-eq0];then
echo "GCC installed!"
else
echo "GCC not installed, ready to install"
yum install -y gcc
fi
Start installing dependencies
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
# Download Python3Wget HTTP: / / https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz# This may waste a lot of time, if there are many machines, you can download it in advance, use the following command
# SCP user_name @ host: / Python_path/Python - 3.7.5. TGZ.
# please use SCP to transfer files without entering password
# or use of Linux Expect
# baidu Ansible will again good ~ tutorial: http://www.ansible.com.cn/
# decompressionThe tar ZXF Python - 3.7.5. TGZGo to the Python source directory
cdPython - 3.7.5Create Python3 installation path
sudo mkdir /usr/local/python3
Generate the configuration file
./configure --prefix=/usr/local/python3
# build install
make & make install
# create soft connection"
ln -s /usr/local/ python3 / bin/python3.7 / usr/bin/python3 ln-s /usr/local/ python3 / bin/pip3.7 / usr/bin/pip3Configure the PIP source
mkdir ~/.pip
cat << EOF > ~/.pip/pip.conf
[global]
index-url = https://pypi.douban.com/simple
[install]
trusted-host=pypi.douban.com
EOF
Copy the code
Small white script, please spray ~