当我做
which pip3
Run Code Online (Sandbox Code Playgroud)
我得到
/usr/local/bin/pip3
Run Code Online (Sandbox Code Playgroud)
但是当我尝试执行时pip3,出现如下错误:
bash: /usr/bin/pip3: No such file or directory
Run Code Online (Sandbox Code Playgroud)
这是因为我最近删除了该文件。现在which命令指向的另一个版本pip3是位于/usr/local/bin但外壳还记得在错误的道路。我如何让它忘记那条路?
该which手册说
which returns the pathnames of the files (or links) which would be executed in the current environment, had its arguments been given as commands in
a strictly POSIX-conformant shell. It does this by searching the PATH for executable files matching the names of the arguments. It does not follow
symbolic links.
Run Code Online (Sandbox Code Playgroud)
双方/usr/local/bin并/usr/bin都在我的PATH变量,而/usr/local/bin/pip3不是一个符号链接,它是一个可执行文件。那么为什么不执行呢?
Eri*_*ouf 49
当您在bash其中运行命令时,它会记住该可执行文件的位置,因此不必PATH每次都再次搜索。所以如果你运行可执行文件,然后更改位置,bash仍然会尝试使用旧位置。您应该能够确认这一点,hash -t pip3这将显示旧位置。
如果您运行hash -d pip3它,它会告诉 bash 忘记旧位置,下次尝试时应该找到新位置。