python的两个版本在linux上。如何使2.7的默认 [英] Two versions of python on linux. how to make 2.7 the default

查看:384
本文介绍了python的两个版本在linux上。如何使2.7的默认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的linuxbox有两个版本的python:

  $ python 
Python 2.6.6 r266:84292,Jul 10 2013,22:48:45)
[gcc 4.4.7 20120313(Red Hat 4.4.7-3)] on linux2
输入help,copyright信用或许可证。
>>>>


$ /usr/local/bin/python2.7
Python 2.7.3(默认,2013年10月8日,15:53:09)
[GCC 4.4.7 20120313(Red Hat 4.4.7-3)] on linux2
更多信息,请输入help,copyright,credits或license。
>>>>

$ which python
/ usr / bin / python
$ ls -al / usr / bin / python
-rwxr-xr-x。 2 root root 4864 Jul 10 22:49 / usr / bin / python

默认版本所以当我键入 python 它让我在2.7?

解决方案



您的发行版在 / usr / bin

中安装了标准系统Python, code>,并且可能有依赖于这个存在的脚本,并由#! / usr / bin / env python 。你可以通过

通常在2.7中运行Python 2.6脚本,但是你想冒险吗?



/ usr / bin 可能会破坏您的包管理器管理包的能力。改变你的 PATH 目录的顺序会影响除了Python之外的许多其他事情。 (实际上,在 / usr / bin 之前有 / usr / local / bin 可能是你实际想要的,但是如果你有它的方式,大概有一个很好的理由。)



但你不需要


$ 更改默认Python以使系统运行2.7 b
$ b

首先,您可以设置一个shell别名:

 别名python = / usr / local / bin / python2.7 

在提示符处键入,或将其放在〜/ .bashrc 如果您希望更改是持久的,现在当您键入 python 运行你选择的2.7,但是当你的系统上的一些程序试图运行一个脚本与 / usr / bin / env python 它运行标准2.6。






或者,只需创建一个虚拟环境从你的2.7(或不同的项目的单独venvs),并在venv里面你的工作。


I've got two versions of python on my linuxbox:

$python
Python 2.6.6 (r266:84292, Jul 10 2013, 22:48:45) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 


$ /usr/local/bin/python2.7
Python 2.7.3 (default, Oct  8 2013, 15:53:09) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

$ which python
/usr/bin/python
$ ls -al /usr/bin/python
-rwxr-xr-x. 2 root root 4864 Jul 10 22:49 /usr/bin/python

How can I make 2.7 be the default version so when I type python it puts me in 2.7?

解决方案

You probably don't actually want to change your default Python.

Your distro installed a standard system Python in /usr/bin, and may have scripts that depend on this being present, and selected by #! /usr/bin/env python. You can usually get away with running Python 2.6 scripts in 2.7, but do you want to risk it?

On top of that, monkeying with /usr/bin can break your package manager's ability to manage packages. And changing the order of directories in your PATH will affect a lot of other things besides Python. (In fact, it's more common to have /usr/local/bin ahead of /usr/bin, and it may be what you actually want—but if you have it the other way around, presumably there's a good reason for that.)

But you don't need to change your default Python to get the system to run 2.7 when you type python.


First, you can set up a shell alias:

alias python=/usr/local/bin/python2.7

Type that at a prompt, or put it in your ~/.bashrc if you want the change to be persistent, and now when you type python it runs your chosen 2.7, but when some program on your system tries to run a script with /usr/bin/env python it runs the standard 2.6.


Alternatively, just create a virtual environment out of your 2.7 (or separate venvs for different projects), and do your work inside the venv.

这篇关于python的两个版本在linux上。如何使2.7的默认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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