服务器上配置python3
说明:一般的服务器上默认情况下会安装pyhton2的版本,就会有yum这个命令
1、首先安装相关包,不然会产生一些错误
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
2、从python的官网上下载相应的数据包
wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz
后面的数据包可以改成你想要的python的版本,直接更改便可
3、查看文件 ls 可以看到当前目录下有你下载的包,包的解压
xz -d Python-3.7.2.tar.xz
第一步解压之后变成了.tar的后缀
tar -xvf Python-3.7.2.tar
4、编译安装命令
#切换到python-3.7.2 的文件夹下
cd Python-3.7.2
#编译命令
./configure prefix=/usr/local/python3
#安装命令
make && make install
安装完毕,/usr/local/目录下就会有python3
5、设置python3的软连接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3.7
这样设置时,你进入python3的环境需要是python3.7,可以如下写:
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
补充A、在4中进行编译时,报如下错误
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for --enable-universalsdk... no
checking for --with-universal-archs... 32-bit
checking MACHDEP... linux
checking for --without-gcc... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/src/pythonSoft/Python-3.3.4':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
解决方式是:需要安装gcc的编译环境
yum install -y gcc
补充B:若初学者操作不当,产生了如下的错误:
yum 安装一个软件包,出现如下错误;
-bash: /usr/bin/yum: /usr/bin/python: bad interpreter: 没有那个文件或目录
解决:查看yum命令
ls -l /usr/bin/yum
-rwxr-xr-x 1 root root 801 6月 23 16:54 /usr/bin/yum
ls -l python
cd /usr/bin/ 找不到python命令
则重新建立一个python的软连接:(查看一下自己的/usr/bin下面的版本 ls python*)
ln -s /usr/bin/python2.6 /usr/bin/python













网友评论