I'm on OS X and I'm trying to get python3 working in sublime. I installed python3 via homebrew and I installed numpy for both python and python3 using pip. In order to be able to build python3 I added the following build file for 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"
}
Finally I'm trying out the build system on the following test file:
#test.py
import numpy
def square(x):
return x * x
if __name__ == '__main__':
print("test: square(42) ==", square(42))
If I build this with the build system set to python (which uses the OS X default version of python 2.7.8) then I get the following (correct) output when I build in sublime:
('test: square(42) ==', 1764)
[Finished in 0.1s]
However, if I set my build system to build with python3 I get the following strange results when I build in 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]
I still get the correct output but also get a bunch of command not found. What's even stranger, if I save this script and run it directly from the terminal using python test.py
for python 2.7.8 or using python3 test.py
for python 3 I get the correct output in the terminal. Additionally, if I remove import numpy
from test.py I no longer get any of the command not found errors in my sublime output.
This problem seems to only show up in sublime using python3 with the above build file and only when I'm trying to import a library installed with pip. If I change the above import in test.py to sys then it will build in sublime without any error messages.
I think I have an answer for you.
Your path variable
"path": "/usr/local/Cellar/python3/3.4.2_1/bin",
needs to append to the existing $PATH. Simply replacing that line in your build file with
"path": "$PATH:/usr/local/Cellar/python3/3.4.2_1/bin",
fixed it for me.
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加