安装Python3
安装依赖
$ yum install zlib zlib-devel openssl-devel libffi-devel
下载介质
编辑./Modules/Setup取消ssl注释
SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
编译安装
$ ./configure --prefix=/usr/local/python3
$ make && make install -j 4
添加环境变量
$ echo "export PATH=$PATH:/usr/local/python3/bin" >>/etc/profile
$ source /etc/profile
查看版本
[root@h-luhx-254 packages]# python3 --version
Python 3.8.7
安装Ansible
下载python依赖包
MarkupSafe
Jinja2
six
pycparser
cffi
cryptography
PyYAML
pyparsing
packaging
setuptools
安装依赖包
$ pip3 install MarkupSafe-1.1.1-cp38-cp38-manylinux1_x86_64.whl
$ pip3 install Jinja2-2.11.3-py2.py3-none-any.whl
$ pip3 install six-1.15.0-py2.py3-none-any.whl
$ pip3 install pycparser-2.20-py2.py3-none-any.whl
$ pip3 install cffi-1.14.4-cp38-cp38-manylinux1_x86_64.whl
$ pip3 install cryptography-3.3.1-cp36-abi3-manylinux2010_x86_64.whl
$ pip3 install PyYAML-5.4.1-cp38-cp38-manylinux1_x86_64.whl
$ pip3 install pyparsing-2.4.7-py2.py3-none-any.whl
$ pip3 install packaging-20.9-py2.py3-none-any.whl
$ pip3 install setuptools-53.0.0-py3-none-any.whl
查看安装的包
[root@h-luhx-254 ansible-2.10.5]# pip3 list
Package Version
------------ -------
cffi 1.14.4
cryptography 3.3.1
Jinja2 2.11.3
MarkupSafe 1.1.1
packaging 20.9
pip 20.2.3
pycparser 2.20
pyparsing 2.4.7
PyYAML 5.4.1
setuptools 53.0.0
six 1.15.0
下载ansible和ansible-base
DownLoad Ansible
DownLoad Ansible-base
安装ansible-base
$ tar -xvf ansible-base-2.10.8.tar.gz
$ cd ansible-base-2.10.8
$ python3 setup.py install
安装ansible
$ tar -xvf ansible-2.10.5.tar.gz
$ cd ansible-2.10.5/
$ python3 setup.py install
查看ansible的版本
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/python3/lib/python3.8/site-packages/ansible_base-2.10.8-py3.8.egg/ansible
executable location = /usr/local/python3/bin/ansible
python version = 3.8.7 (default, Apr 27 2021, 16:30:44) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]
编译遇见的错误
安装出现如下错误
Ansible now needs setuptools in order to build. Install it using your package manager (usually python-setuptools) or via pip (pip install setuptools).
查看setup.py的内容
try:
from setuptools import setup, find_packages
from setuptools.command.build_py import build_py as BuildPy
from setuptools.command.install_lib import install_lib as InstallLib
from setuptools.command.install_scripts import install_scripts as InstallScripts
except ImportError:
print("Ansible now needs setuptools in order to build. Install it using"
" your package manager (usually python-setuptools) or via pip (pip"
" install setuptools).", file=sys.stderr)
sys.exit(1)
尝试手动加载
$ python3
Python 3.8.7 (default, Feb 3 2021, 20:53:47)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from setuptools import setup, find_packages
ModuleNotFoundError: No module named '_ctypes'
Python3中有个内置??榻衏types,它是Python3的外部函数库??椋峁┘嫒軨语言的数据类型,并通过它调用Linux系统下的共享库(Shared library)。由于在CentOS7系统中没有安装外部函数库(libffi)的开发链接库软件包,因此我们需要手动安装并重新编译python
$ yum install libffi-devel -y
$ make && make install -j 4