首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

Centos7 Python3安装

下面的操作,按照步骤来就可以了,不要在中途cd 到别的文件目录下,要想查看效果可以用 lsj加上对应的目录,不需要切换进去。 首先不管你当前在哪个目录下,输入以下命令。 [root@localhost /]# cd / [root@localhost /]# 默认Centos7中是有python安装的,但是是2.7版本,我们需要安装py3。我们去看一下默认的py2.7在哪里。 [root@localhost bin]# cd /usr/bin [root@localhost bin]# ls python python python2 python2.7 [root@localhost bin]# 三个显示结果中最后一个是python2.7,实际上这几个文件之间是有依赖关系的。在ls 后面加个 -al参数,如下: [root@localhost bin]# ls -al  python lrwxrwxrwx. 1 root root   33 Oct 21 12:30 python -> python2 lrwxrwxrwx. 1 root root    9 Oct 19 23:55 python2 -> python2.7 -rwxr-xr-x. 1 root root 7136 Aug  4 08:40 python2.7 [root@localhost bin]# 依赖关系很明显就可以看到。我们要安装版本3,首先要把刚才显示的三个python文件中的第一个python给备份一下(不保留源文件,仅保留备份文件就可以) 使用如下命令: [root@localhost bin]# mv python python.bak python文件变成了python.bak文件,bak文件就放这里吧,再也不用管它了。避免以后麻烦,就留在这里不用删除。系统准备好了,接下来,我们要去下载了。 比较推荐下面这种方式,我们在linux上找一个目录,然后使用wget命令下载到这个目录,然后解压->安装。如下: https://www.python.org/ftp/python/   这个是所有的python版本存放的地方。我们想使用哪个版本就用哪个。

05

升级为python3.3.7版本步骤

python环境搭建-Linux系统下python2.7升级python3.3.7步骤 首先Python 查看版本 , 在Linux下特别注意权限问题,创建目录时候切记给予权限 升级步骤 升级为python3.3.7版本步骤 #解压到下载目录,在编译前先在/usr/local建一个文件夹python3(以免覆盖老的版本) [root@svr7 ~]# tar -xf Python-3.3.7rc1.tar.xz [root@svr7 ~]# cd Python-3.3.7rc1/ #进入解压后的文件夹, [root@svr7 Python-3.3.7rc1]#mkdir /usr/local/python3 [root@svr7 Python-3.3.7rc1]#./configure --prefix=/usr/local/python3 [root@svr7 Python-3.3.7rc1]#make && make install 编译完成 #此时没有覆盖老版本,再将原来/usr/bin/python链接改为别的名字 [root@svr7 Python-3.3.7rc1]# mv /usr/bin/python /usr/bin/python_old [root@svr7 Python-3.3.7rc1]# python -bash: /usr/bin/python: 没有那个文件或目录 [root@svr7 Python-3.3.7rc1]#  ln -s /usr/local/python3/bin/python3 /usr/bin/python [root@svr7 Python-3.3.7rc1]# python Python 3.3.7rc1 (default, Sep  7 2017, 21:25:49) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> [root@svr7 Python-3.3.7rc1]# python --version Python 3.3.7rc1 PS:如果不建立新安装路径python3,而是直接默认安装,则安装后的新python应该会覆盖linux下自带的老版本,也有可能不覆盖,具体看安装过程了,这个大家可以自己试验下,当然如果还想保留原来的版本,那么这种方法最好不过了。 注意事项: 这种方法虽然能安装成功,但会导致yum不能正常使用。 解决方法: [root@svr7 Python-3.3.7rc1]#  cp /usr/bin/yum /usr/bin/yum.backup [root@svr7 Python-3.3.7rc1]# vim /usr/bin/yum 修改第一行参数 vi /usr/bin/yum    把  #!/usr/bin/python    修改为:/usr/bin/python_old   或 把  #!/usr/bin/python    修改为:/usr/bin/python2.7 [root@svr7 Python-3.3.7rc1]# yum repolist 已加载插件:langpacks, product-id, search-disabled-repos, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. 源标识                              源名称                                 状态 rhel7                               rhel7-yum                              4,620 repolist: 4,620

02
领券