澳门新浦京娱乐场网站-www.146.net-新浦京娱乐场官网
做最好的网站

Centos系统一整合体安装python流程,编写翻译安装

一、环境

系统:Centos7

Python:3.6.5  自带pip、setuptools

相关连接: http://www.jb51.net/article/113980.htm
基础景况安插:
yum -y install gcc kernel-devel kenel-headers make bzip2 # 安装注重库

查看是还是不是业已安装Python

一:python2.7.12安装

# Centos7默认的 repo有限, 安装epel

二、命令

说的多,不比直接上命令:

 

yum install readline readline-devel readline-static -y
yum install openssl openssl-devel openssl-static -y # 不然导致pip安装战败
yum install sqlite-devel -y
yum install bzip2-devel bzip2-libs -y
yum install patch vim git # 额外的软件
yum install tcl-devel
yum install tk-devel

CentOS 7.二 默许安装了python2.柒.5 因为一些下令要用它举例yum 它使用的是python二.七.5。

 

rpm -ivh

一,安装正视

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 gcc kernel-devel kenel-headers make bzip2 gcc-c zlib zlib-devel libffi-devel

 

演说:不设置重视,会招致局地设置后的难点,比如:pip、setuptools未有设置

参考:

https://www.cnblogs.com/bigriverx/p/8743008.html

https://www.cnblogs.com/zhangxinqi/p/9074546.html

 

安装python3.3

$ sudo mkdir /usr/local/python3 # 制造安装目录
$ wget --no-check-certificate https://www.python.org/ftp/python/3.5.4/Python-3.5.4.tgz #下载源文件。注意:wget获取https的时候要丰盛:--no-check-certificate
$ tar -xzvf Python-3.5.4.tgz # 解压缩包
现阶段得以一贯动用 tar -xvJf P**.tar.xz来解压
$ cd Python-3.6.0 # 进入解压目录

采用 python -V 命令查看一下是或不是安装Python

#获取python2.7.12

设置python3.6只怕使用的信赖

2,下载安装包

mkdir /usr/local/python3

cd /usr/local/python3

wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz

 

表明:也得以在Windows上下载,通过xftp传到linx上

参考:https://jingyan.baidu.com/article/425e69e60cc78abe14fc1640.html

 

编写翻译安装

然后选择命令 which python 查看一下Python可实行文件的职分

wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz

# yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel

叁,解压安装,设置安装路径

tar zxvf Python-3.6.5.tgz

mkdir /usr/local/python365

cd Python-3.6.5

./configure --prefix=/usr/local/python365

make

make install

 

解释:

tar是解压tgz包

./configure --prefix... 是设置python的设置地点

make 是编写翻译源代码,生成目的文件、可实施文件

make install 将编写翻译成功的文书,安装到系统目录,一般为/usl/local/bin

 

./configure --prefix=/usr/local/python3 # 钦命创建的目录

澳门新浦京娱乐场网站 1

 

下载python三.陆编写翻译安装

四,设置软连接

cd  /usr/bin

ll -al python*

mv python python.bak

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

ln -s /usr/local/python365/bin/pip3 /usr/bin/pip

 

解释:

ll -al python*  查看当前目录含有python的文书并展现软连接

mv python python.bak 因为要安装python命令是运营python三,须求把系统自带的备份后去除

ln -s 目的路线 链接路线

 

make 编译

image

#确认保证卫安全装如下软件若是未有请使用yum安装

到python官方网站下载https://www.python.org

5,设置情形变量

vi  /etc/profile

export PATH=$PATH:/usr/local/Python365/bin

 

source  /etc/profile       --centos陆X需求跟新条件陈设

 

表达:编辑处境变量文件,那是恒久设置,也便是Windows系统:系统变量Path

参考:http://www.voidcn.com/article/p-hcyvuwuz-bqy.html

 

make altinstall 不掩盖安装,不提出使用makeinstall 会覆盖

make distclean
恍如make clean,但还要也将configure生成的公文全部删减掉,包涵Makefile。

看得出施行文书在/usr/bin/ 目录下,切换来该目录下举行 ll python* 命令查看

gcc zlib zlib-devel python-devel libffi-devel openssl openssl-devel make automake

下载最新版源码,使用make altinstall,假如利用make install,在系统中将会有八个差异版本的Python在/usr/bin/目录中。那将会促成数不尽难点,而且不佳管理。

6,恢复yum依赖的python2

vi /usr/bin/yum

把文件开头第二行的  #!/usr/bin/python

改成  #!/usr/bin/python二.7  那样就足以了。

 

计划软连接

ln ./pytho3.6_install/bin/python3.6 python3.6 -s

澳门新浦京娱乐场网站 2

 

# wget

柒,更新和测试

python --version

python

pip list

pip install --upgrade pip

 

解释:

python --version 当前python版本号

python  进入python交互情况

pip list 测试pip暗中认可安装的列表,会有香艳指示要翻新

pip install --upgrade pip 更新pip

设置虚拟情形

pip install virtualenv
pip install pipenv

image

gcc     #为编写翻译时使用,假使不设置make会报错

# tar -xzvf Python-3.6.4.tgz -C  /tmp

pipenv安装失利 错误'install_requires' must

pip install -U setuptools

python 指向的是python二.柒

 

# cd /tmp/Python-3.6.4/

布署安装pip,暗中认可源是二.7.五不大概安装pip

  1. 安装重视境遇

zlib    #为设置setuptools时利用,不然会有如下报错:

澳门新浦京娱乐场网站,把Python3.6安装到/usr/local 目录

参照链接:http://blog.csdn.net/hlj19940416/article/details/53195664

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

RuntimeError: Compression requires the (missing) zlib module

# ./configure --prefix=/usr/local/

yum install epel-release

  1. 浏览器张开 https://www.python.org/ftp/python/ 查看最新的Python版本,标志为3.A.B

 

note: 如遇到 "error: no acceptable C compiler found in $PATH"

yum install python-pip

wget https://www.python.org/ftp/python/3.A.B/Python-3.A.B.tgz

openssl  #假设不设置的话用pip安装模块的时候会报错,显示ssl module不可用之类的。。。

[root@localhost Python-3.6.4]# yum install gcc -y

pip install --upgrade pip

  1. 创建Python3的目录

 

# make

安装虚拟情状模块

mkdir /usr/local/python3

 

# make altinstall

链接: https://www.cnblogs.com/justbreaking/p/7103234.html

pip install -i https://pypi.douban.com/simple/
virtualenvwrapper

  1. 解压下载文件并切换目录

# 解压

Note: 如遇错误,请安装注重包。

豆瓣源使用极度:

处理:
pip install -i http://pypi.douban.com/simple/ virtualenvwrapper # 先使用http举办连接
pip install -i https://pypi.douban.com/simple/ virtualenvwrapper# ,再使用https连接

mkdir ~/.virtualenvs
在.bashrc中最终加多
export WORKON_HOME=~/.virtualenvs
source /usr/bin/virtualenvwrapper.sh
source ~/.bashrc

tar -zxvf Python-3.A.B.tgz

cd Python-3.A.B

tar xvf Python-2.7.12.tgz  

zipimport.ZipImportError: can't decompress data; zlib not available

配备python三的虚拟处境work

mkvirtualnenv
mkvirtualenv --python=/usr/local/python3/bin/python3.5 work

  1. 执行

 

make: *** [altinstall] Error 1

配置

ssh-keygen

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

make && make install

# 进入安装目录

[root@localhost Python-3.6.4]# yum install bzip2-devel -y

布局二个版本共存

$ sudo ln -s /usr/local/python3/bin/python3 /usr/bin/python3 #成立python叁 的软链接,那样就足以因此 python 命令使用 Python 2,python三来使用 Python 三。

  1. 成立Python三的软链接

cd Python-2.7.12

[root@localhost Python-3.6.4]# yum install zlib-devel -y

修改默以为 Python 叁

$ sudo mv python python.bak
$ sudo ln -s /usr/local/python3/bin/python3 /usr/bin/python #创造python叁 的软链接
$ sudo vi /usr/bin/yum #因为 yum 使用 Python 二,因而替换为 Python 叁后或许不可能符合规律办事,由此修改 yum 配置文件。将第1行钦点的 python 版本改为 python二.7(#!/usr/bin/python 改为 #!/usr/bin/python2.7)

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

 

[root@localhost Python-3.6.4]# yum install zlib2 -y

  1. 成立Pip三的软链接

# 配置软件生成Makefile

[root@localhost Python-3.6.4]# yum install zlib -y

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

sudo ./configure  


  1. 测试命令 python三 和 pip3

--prefix=/usr/local/python2.7 

python三 安装成功,音信如下:

python3

pip3

--with-zlib=/usr/local/include 

。。。。

安装保留了原python命令调用python二

 

Collecting setuptools

安装落成

 

Collecting pip

# 编译安装

Installing collected packages: setuptools, pip

make && make install

Successfully installed pip-9.0.1 setuptools-28.8.0

 


# 进入到python安装头文件目录

python三.陆顺序的实行文书:/usr/local/bin/python3.陆

cd /usr/local/python2.7/include/python2.7/

python三.6应用程序目录:/usr/local/lib/python三.陆

 

pip三的实践文书:/usr/local/bin/pip3.陆

# 进入可举办二进制文件目录

pyenv三的实行文书:/usr/local/bin/pyenv-三.六

cd /usr/bin/

[root@localhost Python-3.6.4]# whereis pip

 

pip: /usr/local/bin/pip3.6

# 重命名旧版本

[root@localhost Python-3.6.4]#

sudo mv python2.6 python2.6.6

更改/usr/bin/python链接 (默认是Python2.7)

 

[root@localhost Python-3.6.4]# ls -l /usr/bin/python*

# 修改yum命令的python地点,防止yum的力不从心选择

lrwxrwxrwx. 1 root root    7 Jan 20  2018 /usr/bin/python -> python2

sudo sed -i 's@#!/usr/bin/python@#!/usr/bin/python2.6@' /usr/bin/yum

lrwxrwxrwx. 1 root root    9 Jan 20  2018 /usr/bin/python2 -> python2.7

 

-rwxr-xr-x. 1 root root 7136 Aug  3 20:40 /usr/bin/python2.7

# 设置新装置python的软连接

# cd /usr/bin

sudo ln -s /usr/local/python2.7/bin/python /usr/bin/python

# mv  python python.backup

 

# ln -s /usr/local/bin/python3.6 /usr/bin/python

# 查看是或不是安装成功

# ln -s /usr/local/bin/python3.6 /usr/bin/python3

 

至此,python三曾经设置收尾,测试一下:

[root@localhost bin]# whereis python

python: /usr/bin/python /usr/bin/python2.7 /usr/bin/python.backup /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/local/bin/python3.6m /usr/local/bin/python3.6 /usr/local/bin/python3.6m-config /usr/local/lib/python3.6 /usr/include/python2.7 /usr/share/man/man1/python.1.gz

[root@localhost bin]# python

Python 3.6.4 (default, Jan 20 2018, 03:11:08)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux

Type "help", "copyright", "credits" or "license" for more information.

=======================================================================================

Important:

一.修改剧本

Centos柒下过多脚本是依赖python二.7的,安装完python叁以往,大多脚本不或者寻常使用(举个例子yum), 必要在本子文件开首改造:

#!/usr/bin/python   ===》 #!/usr/bin/python2.7

2.pip3.6 install django

会报错!!

举个例子那样:

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

Collecting xxx

Could not fetch URLhttps://pypi.python.org/simple/xxxx/: There was a problem confirming the ssl certificate: Can’t connect to HTTPS URL because the SSL module is not available. - skipping

Could not find a version that satisfies the requirement xxx (from versions: )

No matching distribution found for xxx

===》solution:

yum install openssl-devel

重新 make & make install 

二:setuptools安装

===> 这表明 要先装python的依赖包,先装python的注重包,先装python的借助包,主要业务说贰回! 然后 make & make install 等等

  Centos柒服务器搭建django项目

下载最新setuptools上转到linux

地址:https://pypi.python.org/pypi/setuptools/36.2.7

解压安装

cd setuptools

Centos系统一整合体安装python流程,编写翻译安装javascript。python setup.py install

ln -s /usr/local/python2.7/bin/pip /usr/bin/pip

 

三:pip安装

 

# 获取pip9.0.1

wget https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9 --no-check-certificate

 

# 解压

tar xvf pip-9.0.1.tar.gz

 

# 安装pip

cd pip-9.0.1

sudo python setup.py install

 

# 设置景况变量,普通用户同样设置

~/.bash_profile加多如下内容:

 

PYTHON_HOME=/usr/local/python2.7

PATH=$PATH:$HOME/bin:$PYTHON_HOME/bin

 

source ~/.bash_profile

 

# 做3个软连接制止sudo pip command not found出现

which pip  #先用which 看一下pip的路径

sudo ln -s /usr/local/python2.7/bin/pip /usr/bin/pip

 

 

# 选拔国内pip源安装软件

始建文件及文件夹在用户家目录下 ~/.pip/pip.conf

加上如下内容:

[global]

index-url =http://pypi.douban.com/simple

 

# 能够安装模块了

pip install PyYAML --trusted-host pypi.douban.com

 

 

=======================================================================================

 

四:pexpect安装

pip install pexpect

本文由澳门新浦京娱乐场网站发布于www.146.net,转载请注明出处:Centos系统一整合体安装python流程,编写翻译安装