First, the source installation
1. Install the basic environment
yum -y install zlib-devel bzip2-devel openssl-devel sqlite-devel readline-devel make
2. Download Source Package
wget https://www.python.org/ftp/python/3.6.7/Python-3.6.7.tar.xz
3. Extract the installation, and enter the file directory
-
tar -xf Python-3.6.7.tar.xz cd Python-3.6.7/
4. Modify the configuration file
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
./configure --enable-shared
make -j 2 && make install
# -j cpu核心数 指定cpu核心数,会加快编译
Second, configure shared library files
1. Set the shared library directory for all users
Open the configuration file with vim editor /etc/profile.d/python3_lib.sh
vim /etc/profile.d/python3_lib.sh
Add the following to the file:
# python3.6 共享库目录
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/bin
Continue to edit the document reads as follows /etc/ld.so.conf.d/python3.conf
/usr/local/bin
Execute the command to load the configuration
ldconfig
Run the following command, the environment variable to take effect
-
source /etc/profile
-
#此条命令只能使本shell生效,若要使子shell生效,需要重启机器
Test python
[root@localhost tmp]# python3
Python 3.6.7 (default, Dec 24 2018, 10:42:15)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print ('hello world')
hello world
>>> exit()
Test pip3
[root@localhost tmp]# pip3 -V
pip 10.0.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)