Sublime 3: Strange output using build system for Python3

I am on OS X and I am trying to get python3 to work in a sublime way. I installed python3 via homebrew and I installed numpy for python and python3 using pip. 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 am trying to create a build system in 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 a build system installed on python (which uses the default OS X 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 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 am still getting correct output but also getting a bunch of command not found. What's even weirder, 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. Also, if I import numpy

remove from test.py, I no longer get any of the commands that didn't find errors in my sublime output.

This problem only seems to show up in sublime use of python3 with the above build file and only when I try to import a library installed with pip. If I change the above import in test.py to sys then it builds in an elevated state with no error messages.

+3


source to share


1 answer


I think I have an answer for you.

Your path variable

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

      



must be added to the existing $ PATH. By simply replacing this line in your build file

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

      

fixed it for me.

+7


source







All Articles