开发者

How do I change where Bash looks for Python in Linux?

开发者 https://www.devze.com 2023-02-21 21:04 出处:网络
I just updated my ReadyNas from python 2.3.5 to python 2.6.6. The upgrade placed the new version in the /usr/local/bin directory. So

I just updated my ReadyNas from python 2.3.5 to python 2.6.6. The upgrade placed the new version in the /usr/local/bin directory. So

  • /usr/local/bin/python is Python 2.6.6
  • /usr/bin/python is Python 2.3.5

When I type python at a bash prompt tries to run /usr/bin/python or my old version. I relocated my old version, a开发者_运维知识库nd now I get:

bash: /usr/bin/python: No such file or directory

How can I change where bash looks for python? How is bash currently deciding that when I type python that it only looks in /usr/bin for python?


Your PATH environment variable. It has a list of directories which bash searches (in the same order) when it's looking for an program to execute. Basically you want to put /usr/local/bin at the start of your PATH environment variable. Add the following to your ~/.bashrc file:

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

You can have a look at the current setting by running the set command in bash.

Alternatively, you can simply rename /usr/bin/python to /usr/bin/python2.3 and create a symlink pointing to the new version, e.g.

ln -s /usr/local/bin/python /usr/bin/python


I don't think it's BASH responsibility to choose the default version for the Python interpreter.

If you're the administrator, the cleanest way to do this is to use a symbolic link in /usr/bin/python pointing to the appropiate version. Avoid replacing the actual binaries if possible.

If you're not, then add a bin folder somewhere you have access to, and prepend it to the $PATH environment variable. Then create a symlink to the desired version of the python interpreter.

Cheers!

0

精彩评论

暂无评论...
验证码 换一张
取 消