注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

God is U 做自己的上帝

富原孤島--只发优质级的文章

 
 
 

日志

 
 

Centos7安装python3、配置pip3、安装Django2  

2017-12-20 09:40:09|  分类: [网络人生] |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
OS:Centos7.4
python:python3.6
pip:pip9.0.1
一、背景
Centos7自带的python是2.7,需要再安装个python3,要注意链接和依赖。
二、安装python3

[root@iZwz96ioq7k0wp5bguxmcgZ ~]# yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel

[root@iZwz96ioq7k0wp5bguxmcgZ ~]# wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz

[root@iZwz96ioq7k0wp5bguxmcgZ ~]# tar -xzvf Python-3.6.0.tgz -C /tmp

[root@iZwz96ioq7k0wp5bguxmcgZ ~]# cd /tmp/Python-3.6.0/

[root@iZwz96ioq7k0wp5bguxmcgZ ~]# ./configure --prefix=/usr/local

[root@iZwz96ioq7k0wp5bguxmcgZ ~]# make

[root@iZwz96ioq7k0wp5bguxmcgZ ~]# make altinstall

//配置python3的链接

[root@iZwz96ioq7k0wp5bguxmcgZ ~]# cd /usr/bin

[root@iZwz96ioq7k0wp5bguxmcgZ ~]# mv python python.backup

[root@iZwz96ioq7k0wp5bguxmcgZ ~]# ln -s /usr/local/bin/python3.6 /usr/bin/python

[root@iZwz96ioq7k0wp5bguxmcgZ ~]# ln -s /usr/local/bin/python3.6 /usr/bin/python3


//测试python2和python3

[root@iZwz96ioq7k0wp5bguxmcgZ ~]# python2
Python 2.7.5 (default, Aug 4 2017, 00:39:18)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@iZwz96ioq7k0wp5bguxmcgZ ~]# python
Python 3.6.0 (default, Dec 19 2017, 15:13:58)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@iZwz96ioq7k0wp5bguxmcgZ ~]#


要同时修改Yum,以下经过验证。
//更改yum脚本的python依赖
# cd /usr/bin
# ls yum*
yum yum-config-manager yum-debug-restore yum-groups-manager
yum-builddep yum-debug-dump yumdownloader
//更改以上文件头为
#!/usr/bin/python 改为 #!/usr/bin/python2
 
//修改gnome-tweak-tool配置文件
vi /usr/bin/gnome-tweak-tool
#!/usr/bin/python 改为 #!/usr/bin/python2
 
//修改urlgrabber配置文件,不修改这个在yum install时就会出报File "/usr/libexec/urlgrabber-ext-down", line 28     except OSError, e:         ^
# vi /usr/libexec/urlgrabber-ext-down
#!/usr/bin/python 改为 #!/usr/bin/python2


三、配置pip3,链接出pip3.6到pip3,同时保留原python2的pip

[root@iZwz96ioq7k0wp5bguxmcgZ ~]# ls /usr/local/bin/p*
/usr/local/bin/pip3.6 /usr/local/bin/python3.6 /usr/local/bin/python3.6m-config
/usr/local/bin/pydoc3.6 /usr/local/bin/python3.6m /usr/local/bin/pyvenv-3.6
[root@iZwz96ioq7k0wp5bguxmcgZ ~]# pip3.6 -V
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
[root@iZwz96ioq7k0wp5bguxmcgZ ~]# ln -s /usr/local/bin/pip3.6 /usr/local/bin/pip3
[root@iZwz96ioq7k0wp5bguxmcgZ ~]# pip3 -V
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
[root@iZwz96ioq7k0wp5bguxmcgZ ~]# pip search django
django-private-files-0.1.2 (0.1.2) - Protected files in django


四、安装Django2

[root@iZwz96ioq7k0wp5bguxmcgZ ~]# pip3 install virtualenv
Collecting virtualenv
Downloading http://mirrors.aliyun.com/pypi/packages/6f/86/3dc328ee7b1a6419ebfac7896d882fba83c48e3561d22ddddf38294d3e83/virtualenv-15.1.0-py2.py3-none-any.whl (1.8MB)
100% |████████████████████████████████| 1.8MB 81.6MB/s
Installing collected packages: virtualenv
Successfully installed virtualenv-15.1.0
[root@iZwz96ioq7k0wp5bguxmcgZ ~]# pip3 install django
Collecting django
Downloading http://mirrors.aliyun.com/pypi/packages/44/98/35b935a98a17e9a188efc2d53fc51ae0c8bf498a77bc224f9321ae5d111c/Django-2.0-py3-none-any.whl (7.1MB)
100% |████████████████████████████████| 7.1MB 4.9MB/s
Collecting pytz (from django)
Downloading http://mirrors.aliyun.com/pypi/packages/a3/7f/e7d1acbd433b929168a4fb4182a2ff3c33653717195a26c1de099ad1ef29/pytz-2017.3-py2.py3-none-any.whl (511kB)
100% |████████████████████████████████| 512kB 78.9MB/s
Installing collected packages: pytz, django
Successfully installed django-2.0 pytz-2017.3
[root@iZwz96ioq7k0wp5bguxmcgZ ~]#


//查看版本和测试

[root@iZwz96ioq7k0wp5bguxmcgZ ~]# pip3 list --format=columns
Package Version
---------- -------
Django 2.0
pip 9.0.1
pytz 2017.3
setuptools 28.8.0
virtualenv 15.1.0
[root@iZwz96ioq7k0wp5bguxmcgZ ~]# python
Python 3.6.0 (default, Dec 19 2017, 15:13:58)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import django

>>>

  评论这张
 
阅读(13)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018