简体   繁体   English

如何以非超级用户身份将 Python 符号链接到 Python2.7

[英]Howto symlink Python to Python2.7 as non-superuser

I am a non-superuser of a linux machine.我是 linux 机器的非超级用户。 Currently it has 2 versions of Python.目前它有 2 个版本的 Python。

When I invoke standard python command it gave version 2.6当我调用标准python命令时,它给出了 2.6 版

$ python
[neversaint@mach71 ~]$ python
Python 2.6.2 (r262:71600, Jan 28 2011, 13:47:39) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

$ which python
/opt/somedir/bin/python

It's only when I invoke with python2.7 it gives the version 2.7只有当我用python2.7调用时,它才会给出 2.7 版本

[neversaint@mach71 ~]$ python2.7
Python 2.7.6 (default, Nov 11 2013, 13:13:15) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

$ which phython2.7
/usr/bin/python2.7

My question is how can I set it such that whenever I call $ python it will give me version 2.7.我的问题是如何设置它以便每当我调用$ python它都会给我 2.7 版。

You can simlink it into some directory both accessible to your user and in your $PATH .您可以将其 simlink 到您的用户和$PATH都可以访问的某个目录中。 For example if /home/<your-username>/local/bin is in your $PATH then you can do例如,如果/home/<your-username>/local/bin在您的$PATH那么您可以执行

ln -s /usr/bin/python2.7 /home/<your-username>/local/bin/python

In this example /home/<your-username>/local/bin should be in your path before /usr/bin .在这个例子中/home/<your-username>/local/bin应该在你的路径中/usr/bin之前。 If there is no such entry in your $PATH you can add it there:如果您的$PATH没有这样的条目,您可以在那里添加它:

export PATH=$HOME/local/bin:$PATH

You can also add this line to .bashrc or similar to activate it on shell start.您还可以将此行添加到.bashrc或类似文件以在 shell 启动时激活它。

使用shell alias , alias python=/usr/bin/python2.7然后 python 将执行该别名的结果。

/usr/bin创建指向 python27 或任何 python 版本的符号链接

sudo ln -s python2.7 python

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM