Linux中安装python3.6和第三方库
如果本机安装了python2,尽量不要管他,使用python3运行python脚本就好,因为可能有程序依赖目前的python2环境,比如yum!!!!!
一、安装python3.6
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
https://www.python.org/downloads/ wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
3.安装python3
# mkdir -p /opt/python3 # tar -zxvf Python-3.6.1.tgz
4.进入解压后的目录,编译安装。
# cd Python-3.6.1 # ./configure --prefix=/opt/python3# make# make install
或者
# make && make install
5.建立python3的软链
# ln -s /opt/python3/bin/python3 /usr/bin/python3
6.将/opt/python3/bin加入PATH
# 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:/opt/python3/bin export PATH
7.生效
# source ~/.bash_profile
8.检查Python3及pip3是否正常可用
# python3 -V Python 3.6.1 # pip3 -V pip 9.0.1 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)
不行的话在创建一下pip3的软链接
# ln -s /opt/python3/bin/pip3 /usr/bin/pip3
二、安装pip以及setuptools
丰富的第三方库是python的优势所在,为了更加方便的安装第三方库,使用pip命令,我们需要进行相应的安装。
1、安装pip前需要前置安装setuptools
wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26 tar -zxvf setuptools-19.6.tar.gz cd setuptools-19.6 python3 setup.py build python3 setup.py install
报错: RuntimeError: Compression requires the (missing) zlib module
我们需要在linux中安装zlib-devel包,进行支持。
yum install zlib-devel
需要对python3.6进行重新编译安装。
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=3a73c4188f8dbad6a1e6f6d44d117eebtar -zxvf pip-8.0.2.tar.gzcd pip-8.0.2python3 setup.py buildpython3 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/heyongboke/p/10255134.html
时间: 2024-08-09 14:10:59