【问题标题】:Sublime 3: Strange output using build system for Python3Sublime 3:使用 Python3 构建系统的奇怪输出
【发布时间】:2015-01-18 21:37:32
【问题描述】:

我在 OS X 上,我正在尝试让 python3 在 sublime 中工作。我通过自制软件安装了 python3,并使用 pip 为 python 和 python3 安装了 numpy。为了能够构建 python3,我为 sublime 添加了以下构建文件:

{
    "path": "/usr/local/Cellar/python3/3.4.2_1/bin",
    "cmd": ["python3", "-u", "$file"],
    "env":{},
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python"
}

最后我在下面的测试文件上尝试构建系统:

#test.py
import numpy

def square(x):
    return x * x

if __name__ == '__main__':
    print("test: square(42) ==", square(42))

如果我在构建系统设置为 python(它使用 OS X 默认版本的 python 2.7.8)的情况下构建它,那么当我在 sublime 中构建时,我会得到以下(正确的)输出:

('test: square(42) ==', 1764)
[Finished in 0.1s]

但是,如果我将构建系统设置为使用 python3 构建,我在 sublime 中构建时会得到以下奇怪的结果:

sh: sysctl: command not found
sh: grep: command not found
sh: sw_vers: command not found
sh: grep: command not found
test: square(42) == 1764
[Finished in 0.1s]

我仍然得到正确的输出,但也得到了一堆找不到的命令。更奇怪的是,如果我保存这个脚本并使用python test.py 用于python 2.7.8 或使用python3 test.py 用于python 3 直接从终端运行它,我会在终端中得到正确的输出。此外,如果我从 test.py 中删除 import numpy,我的 sublime 输出中将不再出现任何 command not found 错误。

这个问题似乎只出现在使用 python3 和上述构建文件的 sublime 中,并且只有当我尝试导入使用 pip 安装的库时。如果我将 test.py 中的上述导入更改为 sys,那么它将在 sublime 中构建而不会出现任何错误消息。

【问题讨论】:

    标签: macos python-3.x numpy sublimetext sublimetext3


    【解决方案1】:

    我想我有一个答案给你。

    你的路径变量

        "path": "/usr/local/Cellar/python3/3.4.2_1/bin",
    

    需要附加到现有的 $PATH。只需将构建文件中的该行替换为

        "path": "$PATH:/usr/local/Cellar/python3/3.4.2_1/bin",
    

    帮我修好了。

    【讨论】:

    • 解决了,谢谢!任何线索没有 $PATH 它在做什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-21
    • 2015-03-01
    • 2013-10-14
    • 1970-01-01
    • 2014-07-07
    • 1970-01-01
    相关资源
    最近更新 更多