我在 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 输出中收到任何未找到命令的错误。
这个问题似乎只出现在使用带有上述构建文件的 python3 的 sublime 中,并且仅当我尝试导入使用 pip 安装的库时才会出现。如果我将 test.py 中的上述导入更改为 sys,那么它将在 sublime 中构建而不会出现任何错误消息。
最佳答案
我想我有一个答案可以告诉你。
你的路径变量
"path": "/usr/local/Cellar/python3/3.4.2_1/bin",
需要附加到现有的 $PATH。只需将构建文件中的那一行替换为
"path": "$PATH:/usr/local/Cellar/python3/3.4.2_1/bin",
帮我修好了。
关于macos - Sublime 3 : Strange output using build system for Python3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27049538/