linux - 执行已知已安装的可执行文件时遇到问题

标签 linux command-line pyqt qml

我最近在我的 Arch 系统上安装了 PyQt4 和 PyQt5,但是当我在终端中运行“qmlviewer”时,它返回:

qmlviewer: could not exec '/usr/lib/qt/bin/qmlviewer': No such file.

我知道我有 qmlviewer - locate 返回我有 qmlviewer 的几个目录。它只是不在我的终端正在执行的目录中。如何让我的终端尝试从实际所在的目录执行 qmlviewer?

最佳答案

bash 跟踪命令所在的位置。 (否则它必须每次都搜索 PATH。)当可执行文件被移动时(如升级过程中可能发生的情况),shell 将不知道其路径信息已过时。解决方案是运行 hash -r 来清除 shell 内存中的路径位置。下次您尝试运行可执行文件时,bash 将从头开始搜索 PATH 来查找它。

我们将进行一些实际的演示。让我们创建一个名为 cmd1 的新命令:

# cp /bin/date /bin/cmd1
# cmd1
Tue Mar 18 22:27:23 PDT 2014

bash 必须搜索 PATH 才能找到 cmd1,但是一旦完成,它就会记住,如 type 命令所示:

# type cmd1
cmd1 is hashed (/bin/cmd1)

现在,让我们通过移动命令来欺骗 bash:

# mv /bin/cmd1 /usr/bin/cmd1
# cmd1
bash: /bin/cmd1: No such file or directory

解决方案如下:

# hash -r
# cmd1
Tue Mar 18 22:28:20 PDT 2014
# type cmd1
cmd1 is hashed (/usr/bin/cmd1)

man bash的相关部分是:

 hash -rv command ...
        The shell maintains a hash table which remembers the loca‐
        tions of commands.  With no arguments whatsoever, the hash
        command prints out the contents of this table.  Entries
        which have not been looked at since the last cd command
        are marked with an asterisk; it is possible for these
        entries to be invalid.

        With arguments, the hash command removes the specified
        commands from the hash table (unless they are functions)
        and then locates them.  With the -v option, hash prints
        the locations of the commands as it finds them.  The -r
        option causes the hash command to delete all the entries
        in the hash table except for functions.

POSIX 中包含了 hash 函数的功能稍少的版本。 .

关于linux - 执行已知已安装的可执行文件时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22466032/

相关文章:

linux - 如何理解内核中 "page_align"的宏?

python - 将参数传递给 QWidget.mousePressEvent

html - 如何在 QTextBrowser (Html) 中设置文本颜色? (PyQt)

android - cordova 构建 android 在 :app:mergeReleaseResources step with "Daemon startup failed" message 上失败

php 页面未在/usr/local/中打开

c++ - 更新到 1.30 后,我无法在 Linux 上使用 VS Code 调试项目

linux - 如何监控访问特定文件的进程?

java - 使用依赖项运行可执行 jar 时出现问题

linux - 在特定终端中通过 Perl 运行 shell 命令

python-3.x - QSortFilterProxyModel 过滤完成信号