在bash中,"其中"给出了一个不正确的路径 - Python版本 [英] In bash, "which" gives an incorrect path - Python versions

查看:212
本文介绍了在bash中,"其中"给出了一个不正确的路径 - Python版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释如何Python 2.6中可以得到默认我的机器上运行?它看起来像蟒蛇点至2.7,所以它看起来像不给我正确的信息。

 〜>蟒蛇--version
Python的2.6.5
〜>这蟒蛇
的/ opt / local / bin目录/蟒蛇
〜>的/ opt / local / bin目录/蟒蛇--version
Python的2.7.2
〜> ls -l命令的/ opt / local / bin目录/蟒蛇
lrwxr-XR-X 1根admin 24 10月12日16:02的/ opt / local / bin目录/蟒蛇 - > /opt/local/bin/python2.7

当我产生一个错误,我看到了什么是真正得到运行。为什么会这样?

 〜>蟒蛇 - 错误决策,论证
未知选项:-e
用法:/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python [选项] ... [-C CMD | -m MOD |文件| - ] [参数] ...
尝试`蟒蛇-h以获取更多信息。

我该如何纠正呢?

----编辑:----

在意见建议:

 〜>别号
别名CP ='CP -i
别名GCC ='GCC -Wall
〜>键入python
蟒蛇是/ opt / local / bin目录/蟒蛇


解决方案

Bash使用的<一个href=\"http://www.cyberciti.biz/tips/how-linux-or-unix-understand-which-program-to-run-part-i.html#hashtables\">internal哈希表优化 $ PATH 查找。当您使用相同的名称安装新程序为(在这种情况下,蟒蛇)现有程序早些时候在你的 $ PATH ,击不知道这件事,并继续使用旧的。在的可执行文件进行全 $ PATH 搜索并打印出预期的结果。

要解决此问题,运行命令散-d蟒蛇。这将从击的哈希表中删除蟒蛇并迫使它做一个完整的 $ PATH 搜了下一次调用它。另外,您还可以运行散-r 来完全清除哈希表。

键入内置会告诉你,一个给定的命令怎么会间preTED。如果说,一个命令被散列,这意味着Bash是要跳过 $ PATH可执行搜索。

Can anyone explain how python 2.6 could be getting run by default on my machine? It looks like python points to 2.7, so it seems like which isn't giving me correct information.

~> python --version
Python 2.6.5
~> which python
/opt/local/bin/python
~> /opt/local/bin/python --version
Python 2.7.2
~> ls -l /opt/local/bin/python
lrwxr-xr-x  1 root  admin  24 12 Oct 16:02 /opt/local/bin/python -> /opt/local/bin/python2.7

When I generate an error, I see what's really getting run. Why could this be?

~> python -error-making-argument
Unknown option: -e
usage:     /Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.

And how can I correct it?

----Edit:----

From suggestions in comments:

~> alias
alias cp='cp -i'
alias gcc='gcc -Wall'
~> type python
python is /opt/local/bin/python

解决方案

Bash uses an internal hash table to optimize $PATH lookups. When you install a new program with the same name as an existing program (python in this case) earlier in your $PATH, Bash doesn't know about it and continues to use the old one. The which executable does a full $PATH search and prints out the intended result.

To fix this, run the command hash -d python. This will delete python from Bash's hash table and force it to do a full $PATH search the next time you invoke it. Alternatively, you can also run hash -r to clear out the hash table entirely.

The type builtin will tell you how a given command will be interpreted. If it says that a command is hashed, that means that Bash is going to skip the $PATH search for the executable.

这篇关于在bash中,&QUOT;其中&QUOT;给出了一个不正确的路径 - Python版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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