macos – Sublime 3:使用Python3构建系统的奇怪输出
我在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进行构建,会得到以下奇怪的结果: 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 2.7.8的python test.py或者使用python3的python3 test.py直接从终端运行它,我会在终端中获得正确的输出.另外,如果我从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", 为我修好了. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |