centos6.8 裸机安装Python3环境

1.安装依赖库

yum groupinstall 'Development Tools'
yum install -y ncurses-libs zlib-devel mysql-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

2.下载源码包,编译安装

下载地址:https://www.python.org/downloads/release/python-370/,选择Gzipped source tarball

./configure --prefix=/usr/local/python3 --enable-optimizations

make && make install

3.解决报错

ModuleNotFoundError: No module named '_ctypes'

    python3.7版本需要新的依赖库libffi-devel
    安装依赖库解决:yum install libffi-devel -y
    重新编译安装

4.建立软链接

ln -s /usr/local/python3/bin/python3 /usr/bin/python
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip

5.更改pip源(大公司存在网络限制)

cd ~
mkdir .pip && cd .pip
vim pip.conf
# 添加下面的代码
[global]
index-url=http://xxxx.com/pypi/simple
trusted-host=xxxx.com  # 设置可信任站点,防止pip install报警

6.设置PYTHONPATH(解决无法导入第三方包)

vim ~/.bashrc
# 末行添加如下代码
export PYTHONPATH=$PYTHONPATH:"/usr/local/python3/lib/python3.7/set-packages"
# 重新加载该文件
source ~/.bashrc

完成以上步骤就可以正常使用Python3的环境了!!

你可能感兴趣的:(Python运维)