安装python3及安装遇到的问题

 1、安装python3相关命令。 

mkdir -p /usr/local/python3
cd /usr/local/python3
wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
tar -zxvf Python-3.7.2.tgz
cd Python-3.7.2
./configure --enable-optimizations    # bash ./configure --prefix=/usr/local/python3
make && make install

如果提示See `config.log' for more details,说明缺少gcc文件。

checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for python3.7... no
checking for python3... no
checking for python... python
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... checking for --without-gcc... no
checking for --with-icc... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/python3/Python-3.7.2':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

安装gcc。 

yum install -y gcc

如果提示can't decompress data; zlib not available,说明缺少zlib*文件。

zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] Error 1

 安装zlib*。

yum -y install zlib*

如果提示No module named '_ctypes',说明缺少libffi-devel -y文件。

ModuleNotFoundError: No module named '_ctypes'
make: *** [install] Error 1

安装libffi-devel -y。

yum install libffi-devel -y

2、建立python3的软链

ln -s /usr/local/python3/bin/python3 /usr/bin/python3

3、进入vim编辑页面

vim ~/.bash_profile

将/usr/local/python3/bin加入PATH

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/usr/local/python3/bin

export PATH

按ESC,输入:wq回车退出。

修改完记得执行行下面的命令,让上一步的修改生效:

source ~/.bash_profile

3、检查Python3及pip3是否正常可用:

# python3 -V
Python 3.7.2
# pip3 -V
pip 18.1 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)

猜你喜欢

转载自blog.csdn.net/wangctes/article/details/88550762