How to set which version of python sublime text us

2019-02-01 12:40发布

问题:

I have been teaching myself python and started out using python 2.7.5 and Sublime Text 2. I recently enrolled in a class and they are using python 3.4. I downloaded and installed python 3.4 onto my mac, but am having trouble figuring out how to make Sublime Text use python 3 instead of 2.7. I used..

import sys
print sys.version

to determine which version of python ST was using. It reports back with 2.7.5.

How do I force ST to use python 3?

If I have not included enough information, please don't hesitate to ask.

回答1:

Found this on Google.

Create the file ~/.config/sublime-text-2/Packages/Python/Python3.sublime-build:

{
    "cmd": ["python3", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python"
}

You should then be able to choose the Python3 build system.

If that doesn't work, try this:

{
    "cmd": ["python3", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python",
    "encoding": "utf8",
    "path": "/Library/Frameworks/Python.framework/Versions/3.3/bin/"
}