[root@localhost soft]# tar -xzvf Python-3.7.4.tgz
[root@localhost soft]# mv Python-3.7.4 py374
[root@localhost soft]# cd py374/
[root@localhost py374]# ./configure prefix=/usr/local/python3
checking for the getrandom() function... no
checking for pkg-config... /usr/bin/pkg-config
checking for openssl/ssl.h in /usr/local/ssl... no
checking for openssl/ssl.h in /usr/lib/ssl... no
checking for openssl/ssl.h in /usr/ssl... no
checking for openssl/ssl.h in /usr/pkg... no
checking for openssl/ssl.h in /usr/local... no
checking for openssl/ssl.h in /usr... no
checking whether compiling and linking against OpenSSL works... no
checking for --with-ssl-default-suites... python
configure: creating ./config.status
config.status: creating Makefile.pre
config.status: creating Misc/python.pc
config.status: creating Misc/python-config.sh
config.status: creating Modules/ld_so_aix
config.status: creating pyconfig.h
creating Modules/Setup
creating Modules/Setup.local
creating Makefile
If you want a release build with all stable optimizations active (PGO, etc),
please run ./configure --enable-optimizations
[root@localhost py374]#
[root@localhost py374]# make && make install
(cd /usr/local/python3/bin; ln -s pyvenv-3.7 pyvenv)
if test "x" != "x" ; then \
rm -f /usr/local/python3/bin/python3-32; \
(cd /usr/local/python3/bin; ln -s python3.7-32 python3-32) \
fi
rm -f /usr/local/python3/share/man/man1/python3.1
(cd /usr/local/python3/share/man/man1; ln -s python3.7.1 python3.1)
if test "xupgrade" != "xno" ; then \
case upgrade in \
upgrade) ensurepip="--upgrade" ;; \
install|*) ensurepip="" ;; \
esac; \
./python -E -m ensurepip \
$ensurepip --root=/ ; \
fi
Looking in links: /tmp/tmpmokew1il
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-19.0.3 setuptools-40.8.0
[root@localhost py374]#
打印如上信息提示安装成功;需要等待一定的时间。
五、配置全局变量以及python3和python兼容
将python和pip设置为全局变量
ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip3
配置python3 和python2 共存
vi /usr/bin/yum
vi /usr/libexec/urlgrabber-ext-down
将文件开始的#! /usr/bin/python 也修改为#! /usr/bin/python2
六、启动进行测试
[root@localhost py374]# python3
Python 3.7.4 (default, Apr 13 2022, 10:14:04)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1.01 ** 365
37.78343433288728
>>>
七、问题记录
报错1:
在make && make install 之后提示如下报错
File "/tmp/tmpddm600ma/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/__init__.py", line 40, in <module>
File "/tmp/tmpddm600ma/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/autocompletion.py", line 8, in <module>
File "/tmp/tmpddm600ma/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/main_parser.py", line 12, in <module>
File "/tmp/tmpddm600ma/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/commands/__init__.py", line 6, in <module>
File "/tmp/tmpddm600ma/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/commands/completion.py", line 6, in <module>
File "/tmp/tmpddm600ma/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/base_command.py", line 20, in <module>
File "/tmp/tmpddm600ma/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/download.py", line 37, in <module>
File "/tmp/tmpddm600ma/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/utils/glibc.py", line 3, in <module>
File "/home/soft/py374/Lib/ctypes/__init__.py", line 7, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
make: *** [install] Error 1
以上报错需要安装libffi-devel包。执行以下安装命令在重新执行make && make install
yum install libffi-devel -y