Atom 脚本在 Mac 上找不到 Python 3 的路径

Atom Script can't find the path for Python 3 on Mac

当使用 Atom 的脚本插件时,它会出现:

Unable to run

/usr/bin/python3

Did you start Atom from the command line?

atom .

Is it in your PATH?

PATH: /usr/bin/python3:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/bin/python3:/usr/local/share/dotnet:/Library/Frameworks/Mono.framework/Versions/Current/Commands:~/.dotnet/tools

如何让 Atom 识别 Python 3?

我尝试使用 Homebrew 安装 Python 并将其安装到 /usr/local/bin/python3 以及使用终端将所有建议的路径位置添加到 /etc/paths.

您需要正确配置 script package 以使用指向正确 python3 的配置文件。

  1. 打开终端并导航到包含您的脚本的目录。

    $ pwd
    /Users/cerberus/Scripts
    
  2. 获取python3

    的路径
    • 如果您是通过 Homebrew 安装的,那么它应该位于:

      $ python3 -V
      Python 3.7.3
      $ which python3
      /usr/local/bin/python3
      
    • 您还可以检查 Homebrew 是否已更新 PATH 以添加 /usr/local/bin,但除非您对 Python安装,这部分不需要。

      $ echo $PATH
      .../usr/local/bin/:/...
      
  3. 现在,按照package docs

    中的说明从命令行启动Atom

    Make sure to launch Atom from the console/terminal. This gives atom all your useful environment variables. Additionally, make sure to run it with the project path you need.

    $ cd /path/to/scripts
    $ atom .
    

    $ atom /path/to/scripts
    
  4. 转到 > 命令面板 > 切换(或使用 CMD+SHIFT+P)

  5. Select 脚本:运行 选项

  1. 输入脚本的路径和python3命令的路径

NOTE: On my machine, just setting python3 also works. But if you are having problems with your python path, you can try to specify the full path (/usr/local/bin/python3) as shown.

  1. 保存配置文件(例如 "Python3")
  2. 现在,当您想要 运行 您的 Python 脚本时,请使用 Script: 运行 with Profile 命令,然后 select 您刚刚创建的配置文件。

  1. 现在应该可以了。