升级默认的python版本或在Linux中安装另一个python版本 [英] upgrading default python version or install another python version in Linux

查看:59
本文介绍了升级默认的python版本或在Linux中安装另一个python版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想升级python的默认版本,即Linux中的/usr/bin/python .

I want to upgrade python's default version i.e /usr/bin/python in Linux.

我有多个安装为

/usr/bin/python2.7   
/usr/bin/python3.3

但是, python 命令仍然返回 python2.7

# python
Python 2.7 
Type "help", "copyright", "credits" or "license" for more information.
>>>

现在,我已经安装了一个模块,该模块已安装为默认版本 2.7 .

Now, I have installed a module, which got installed in the default version 2.7.

这就是为什么我不能使用 python3.3 script.py,因为它返回缺少模块的错误.

That's why I can't use python3.3 script.py, as it returns error for missing module.

如何将此默认版本更新为 3.3 ?

How to update this default version to 3.3?

是否也可以在/usr/bin/python3.3 中安装模块?

Is there a way to install the module in /usr/bin/python3.3 as well?

已添加:模块为 pexpect-2.3 .

推荐答案

安装新的 python ,默认情况下安装在/usr/local/bin 中.

Installing new python, installs by default in /usr/local/bin.

将此路径添加到PATH之前的默认python路径之前即可解决此问题.

Adding this path to PATH before previous default python's path, solves the problem.

export PATH=/usr/local/bin:$PATH
# This export statement could be added to .bashrc for permanent effect.

这样,旧的python不会被弄乱,而新的python会被安装.

This way old python is not messed and new one is installed.

另外,如果/usr/local/bin中已经存在python,则更改/usr/local/bin/python的符号链接更改为新的/usr/local/bin/python3.3 即可解决此问题.(Python安装通常仅在/usr/local/bin中安装时才创建链接.您可以在/usr/local/bin/python中执行 ls 来验证它是否为链接.因为python安装为/usr/local/bin/python2.7,然后按如下所示创建指向该链接的链接)

Also, If there is already a python present in /usr/local/bin, changing symbolic link of /usr/local/bin/python to new /usr/local/bin/python3.3 solves the problem. (Python install generally only creates link when it installs in /usr/local/bin. You can do ls on /usr/local/bin/python to verify that it is link. Because python is installed as /usr/local/bin/python2.7 and then a link to this is created as below)

/usr/local/bin/python->/usr/local/bin/python2.7

/usr/local/bin/python -> /usr/local/bin/python2.7

/usr/local/bin/python->/usr/local/bin/python3.3

/usr/local/bin/python -> /usr/local/bin/python3.3

当然,应该如上所述将其路径添加到PATH.

Ofcourse, path of this should be added to PATH as already mentioned above.

除非有充分的理由,否则最好不要触摸和混淆/usr/bin/python 版本,除非/usr/bin/python通常不是链接,并且很多人都需要/usr/bin/python操作系统模块.

It's always better to never touch and mess with /usr/bin/python version, unless there is strong reason, because /usr/bin/python is generally not a link and is required by many of os modules.

这篇关于升级默认的python版本或在Linux中安装另一个python版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆