我现在无法在我的项目中导入`commands`

244*_*boy 1 python

在我的项目中,我想导入命令,因此我将以下代码放入我的项目中:

\n\n
import commands\n
Run Code Online (Sandbox Code Playgroud)\n\n

但是我得到了错误:

\n\n
No module named commands less... (\xe2\x8c\x98F1) \nThis inspection detects names that should resolve but don't. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Top-level and class-level items are supported better than instance items.\n
Run Code Online (Sandbox Code Playgroud)\n

raz*_*zdi 5

从文档中:

自版本 2.6 起已弃用:命令模块已在 Python 3 中删除。请改用 subprocess 模块。

您可以点击此链接: https ://docs.python.org/2/library/commands.html

  • 也许另请参阅https://docs.python.org/3/library/subprocess.html?highlight=subprocess#legacy-shell-invocau-functions,它更详细地解释了如何准确地用相应的“子进程”调用替换“命令” ; 尽管您可能还应该考虑用“subprocess.run()”替换这些遗留调用 (3认同)