1. Source code installation
1. Install dependent packages:
[[email protected] ~]# yum groupinstall "Development Tools"
[[email protected] ~]# yum -y install zlib-devel bzip2-devel openssl-devel sqlite-devel readline-devel libffi-devel
2. Download the source package,
go to python's official website python.org
orient/strip%7CimageView2/2/w/1240)]
Click to download directly or copy the link address
[[email protected] ~]# wget https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tar.xz
3. Unzip and install
[[email protected] ~]# tar -xf Python-3.7.6.tar.xz
[[email protected] ~]# cd Python-3.7.6
4. Modify configuration information
4.1 Method 1: Modify directly,
modify the file with vim Python-3.7.6/Modules/Setup.dist
, and remove the comments on the following lines:
readline readline.c -lreadline -ltermcap
SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
4.2 Method 2: Execute the following commands in the shell command prompt
Execute the following commands under [root@qf-cloud-2002 ~]#
sed -ri 's/^#readline/readline/' Modules/Setup.dist
sed -ri 's/^#(SSL=)/\1/' Modules/Setup.dist
sed -ri 's/^#(_ssl)/\1/' Modules/Setup.dist
sed -ri 's/^#([\t]*-DUSE)/\1/' Modules/Setup.dist
sed -ri 's/^#([\t]*-L\$\(SSL\))/\1/' Modules/Setup.dist
5. Start to compile and install
[[email protected] ~]# ./configure --enable-shared
[[email protected] ~]# make -j 1 && make install
-j 当前主机的 cpu 核心数,根据自己的核数可以修改
--Enable-shared specifies the installation of shared libraries. The shared libraries will be used when using other software that needs to call python, such as when
mod_wgsi
connecting Apache and python.
2. Configuration environment
Execute the following commands in sequence
[[email protected] ~]# cmd1='export LD_LIBRARY_PATH='
[[email protected] ~]# cmd2='$LD_LIBRARY_PATH:/usr/local/lib'
[[email protected] ~]# file="/etc/profile.d/python3_lib.sh"
[[email protected] ~]# echo "${cmd1}${cmd2}" >$file
[[email protected] ~]# path="/usr/local/lib"
[[email protected] ~]# file2="/etc/ld.so.conf.d/python3.conf"
[[email protected] ~]# echo ${path} > $file2
Execute the following command to make the environment configuration effective
[[email protected] ~]# ldconfig
[[email protected] ~]# source /etc/profile
3. Test the installation
1. Test python3
[[email protected] ~]# python3 -V
Python 3.7.6
[[email protected] ~]#
#显示的含有python3.7.6就没问题
2. Test pip3
[[email protected] ~]# pip3 -V
pip 20.0.2 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
Output information directory
/usr/local/lib/python3.7/site-packages/
is located in the mounting means for the third party
4. Configure to install third-party modules using local sources
1. Create a hidden directory under the current user's home directory .pip
2. Execute the following commands to facilitate writing to domestic sources:
[[email protected] ~]# echo '[global]' >> ~/.pip/pip.conf
[[email protected] ~]# c1="index-url=https://"
[[email protected] ~]# c2="mirrors.aliyun.com/pypi/simple"
[[email protected] ~]# echo "${c1}${c2}" >> ~/.pip/pip.conf
Watercress Source:
https://pypi.douban.com/simple/
Ali Source:https://mirrors.aliyun.com/pypi/simple
3. test the configuration rows
can install an enhanced version of the interpreteripython
for later testing of this module will use
[[email protected] ~]# pip3 install ipython
------------python3