如果本机安装了python2,尽量不要管他,使用python3运行python脚本就好,因为可能有程序依赖目前的python2环境,
比如yum!!!!!
不要动现有的python2环境!
一. 安装准备
1. 安装依赖环境
# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
2.下载Python3
从官网下载相应的Python版本,目前最新版本为Python3.6.4,点击下载。
也可以通过如下命令下载:
wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
3. 安装第三方包
在Python下载目录依次运行如下命令:
[root@cdh1 opt]# tar zxvf Python-3.6.4.tgz [root@cdh1 opt]# cd Python-3.6.4
个人习惯安装在/usr/local/python3(具体安装位置看个人喜好)
创建目录:
[root@cdh1 Python-3.6.4]# mkdir -p /usr/local/python3 [root@cdh1 Python-3.6.4]# ./configure --prefix=/usr/local/python3 [root@cdh1 Python-3.6.4]# make
[root@cdh1 Python-3.6.4]# make install
make是一个编译命令,如果make的时候出现以下情况
那就是没有找到makefile,你看下configure的时候有没有报错呀,是不是提示有什么依赖的包没有装,先把依赖的包装了,再configure,试试,看有没有makefile
安装依赖包
Python3.6安装报错 configure: error: no acceptable C compiler found in $PATH
安装python的时候出现如下的错误:
[root@master ~]#./configure --prefix=/usr/local/python3.6
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编译环境
1、通过yum安装gcc编译环境:yum install -y gcc
2、本机没有安装yum功能,可下载gcc安装包:https://gcc.gnu.org/
[root@cdh1 Python-3.6.4]# yum install -y gcc
然后再make
[root@cdh1 Python-3.6.4]# make [root@cdh1 Python-3.6.4]# make install
4. 建立python3的软链
[root@cdh1 Python-3.6.4]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
5.并将/usr/local/python3/bin加入PATH
[root@cdh1 Python-3.6.4]# vim ~/.bash_profile
# .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回车退出。
6.修改完记得执行行下面的命令,让上一步的修改生效:
[root@cdh1 Python-3.6.4]# source ~/.bash_profile
7.检查Python3及pip3是否正常可用:
[root@cdh1 Python-3.6.4]# python3 -V
Python 3.6.4
[root@cdh1 Python-3.6.4]# pip3 -V
pip 9.0.1 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)
8.不行的话在创建一下pip3的软链接(我也不清楚这一步有什么用)
# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
二、安装pip以及setuptools
毕竟丰富的第三方库是python的优势所在,为了更加方便的安装第三方库,使用pip命令,我们需要进行相应的安装。
命令如下:
[root@cdh1 Python-3.6.4]#wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
[root@cdh1 Python-3.6.4]#tar -zxvf setuptools-19.6.tar.gz
[root@cdh1 Python-3.6.4]#cd setuptools-19.6
[root@cdh1 setuptools-19.6]#python3 setup.py build
[root@cdh1 setuptools-19.6]#python3 setup.py install
最后试下:
[root@cdh1 Python-3.6.4]#python3
根据自己需求安装模块:
[root@cdh1 Python-3.6.4]# pip3 install .... (requests\ flask)
[root@cdh1 Python-3.6.4]# pip3 install requests
[root@cdh1 Python-3.6.4]# pip3 install flask
[root@cdh1 Python-3.6.4]# pip3 install gevent
[root@cdh1 Python-3.6.4]# pip3 install redis
[root@cdh1 Python-3.6.4]# pip3 install redis-py-cluster
[root@cdh1 Python-3.6.4]# pip3 install pymongo
[root@cdh1 Python-3.6.4]# pip3 install pillow
[root@cdh1 Python-3.6.4]# pip3 install numpy
[root@cdh1 Python-3.6.4]# pip3 install tensorflow
上下传文件命令:
yum -y install lrzsz
解压缩文件:
yum install -y unzip zip
如果前面没布置好环境的话,继续操作如下方法:
报错: RuntimeError: Compression requires the (missing) zlib module
我们需要在linux中安装zlib-devel包,进行支持。
yum install zlib-devel
需要对python3.5进行重新编译安装。
cd python3.6.1
make && make install
又是漫长的编译安装过程。
重新安装setuptools
python3 setup.py build
python3 setup.py install
2、安装pip
命令如下:
wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb
tar -zxvf pip-8.0.2.tar.gz
cd pip-8.0.2
python3 setup.py build
python3 setup.py install
如果没有意外的话,pip安装完成。
如果没有搞好环境的话,会碰见亲切的报错:
pip3 install paramiko
报这个错
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
然后开始进行如下操作
yum install openssl
yum install openssl-devel
cd python3.6.1
make && make install
三.还可以参考下面同学的链接
https://www.cnblogs.com/kimyeee/p/7250560.html
远程拷贝命令:
[root@iZbp17myadp30d5qukpv2wZ opt]# scp Python-3.6.4.tgz [email protected]:/opt/
The authenticity of host '47.97.37.7 (47.97.37.7)' can't be established.
ECDSA key fingerprint is e7:ac:cd:3b:3c:3e:b2:e1:0f:a1:4e:2d:81:25:1c:9b.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': y
Please type 'yes' or 'no': yes
Warning: Permanently added '47.97.37.7' (ECDSA) to the list of known hosts.
[email protected]'s password:
Python-3.6.4.tgz
===========================================================================
安装上传下载文件命令:
yum -y install lrzsz
在Linux系统下,用unzip命令解压缩的时候,出现错误:
unzip: command not found
其原因是找不到zip压缩软件
yum install -y unzip zip
脚本执行权限
chmod +x curl_ip.sh (filename)
./ filename