【问题标题】:Sublime Text 3 won't recognize my python installation in another driveSublime Text 3 无法识别我在另一个驱动器中安装的 python
【发布时间】:2018-12-29 03:01:36
【问题描述】:

我已经在 D: 驱动器中安装了 Python 3.7.2(为程序分开)。安装 Sublime Text 的便携版后,它无法识别我的 Python 安装,当我运行 Python 程序时出现以下错误:(顺便说一句,我尝试了其他问题中建议的其他方法,但它仍然无法识别我的安装运行。我仍然可以编辑代码,但不能运行它)。

'python' is not recognized as an internal or external command,
operable program or batch file.
[Finished in 0.1s with exit code 1]
[shell_cmd: python -u "D:\Program Files\Python\Python37\MyScripts\GameIdea.py"]
[dir: D:\Program Files\Python\Python37\MyScripts]
[path: c:\program files (x86)\intel\intel(r) management engine components\icls\;c:\program files\intel\intel(r) management engine components\icls\;c:\windows\system32;c:\windows;c:\windows\system32\wbem;c:\windows\system32\windowspowershell\v1.0\;c:\windows\system32\openssh\;c:\program files (x86)\intel\intel(r) management engine components\dal;c:\program files\intel\intel(r) management engine components\dal;c:\program files (x86)\intel\intel(r) management engine components\ipt;c:\program files\intel\intel(r) management engine components\ipt;%systemroot%\system32;%systemroot%;%systemroot%\system32\wbem;%systemroot%\system32\windowspowershell\v1.0\;%systemroot%\system32\openssh\;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Users\Arnold\AppData\Local\Microsoft\WindowsApps;]

【问题讨论】:

    标签: sublimetext3


    【解决方案1】:

    Sublime 在尝试运行外部程序时不会寻找它们;它只是告诉底层操作系统“运行这个程序”。您看到的错误消息是一条 Windows 错误消息,告诉您您告诉它执行某些操作,但它不知道它是什么。

    分解您在构建输出面板中看到的内容:

    'python' is not recognized as an internal or external command, operable program or batch file.
    [Finished in 0.1s with exit code 1]
    

    这是 Windows 告诉你“你试图运行一个名为 python 的程序,但我不知道那个程序是什么。它似乎不是我知道的内部程序,也不是似乎是一个已知的外部程序。

    [shell_cmd: python -u "D:\Program Files\Python\Python37\MyScripts\GameIdea.py"]
    [dir: D:\Program Files\Python\Python37\MyScripts]
    

    这是一个 Sublime 诊断,告诉您 Sublime 尝试执行的确切命令以及当时的“当前”目录。

    [路径:c:\program files (x86)\intel\intel(r) 管理引擎组件\icls\;c:\program files\intel\intel(r) 管理引擎组件\icls\;c:\ windows\system32;c:\windows;c:\windows\system32\wbem;c:\windows\system32\windowspowershell\v1.0\;c:\windows\system32\openssh\;c:\program files (x86) \intel\intel(r) 管理引擎组件\dal;c:\program files\intel\intel(r) 管理引擎组件\dal;c:\program files (x86)\intel\intel(r) 管理引擎组件\ ipt;c:\program files\intel\intel(r) 管理引擎组件\ipt;%systemroot%\system32;%systemroot%;%systemroot%\system32\wbem;%systemroot%\system32\windowspowershell\v1.0\ ;%systemroot%\system32\openssh\;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Users\Arnold\AppData\Local\Microsoft \WindowsApps;]

    这是操作系统(在本例中为 Windows)它知道查找程序的位置列表,这是错误消息所指的“外部命令”。仔细观察,这些地点似乎都没有在驱动器上D: 或根本没有提到Python

    因此,当 Sublime 告诉 Windows 它需要运行 python 时,Windows 找不到它,因为此处列出的任何文件夹中的任何位置都没有出现任何名为 python 的内容。

    解决问题的方法是确保系统PATH包含Python解释器所在的位置。具体操作方式取决于您使用的操作系统,在 Windows 的情况下也可能略有不同,具体取决于您运行的 Windows 版本。

    一般来说,为了让外部命令在 Sublime 中工作,您需要能够打开命令提示符、终端等并输入该命令并使其工作;如果它不运行程序,Sublime 也将无法运行它。

    【讨论】:

    • 通过使用 setx 将 d: 驱动器添加到路径,设法将其修补在一起。奇迹般有效。非常感谢您向我解释这一点。
    最近更新 更多