I am able to set python3.2 for the build command in sublime text 2(and build with python3.2), but when invoking the console with cmd-` the interpreter is mac's default 2.6 version. Any help is greatly appreciated!
问题:
回答1:
The console in Sublime Text 2 uses the internal version of Python, which is 2.6. There is no way to change it without breaking a whole bunch of stuff. There is a workaround, though. If you just want a Python console within ST2, use the awesome SublimeREPL package, which can also be installed through Package Control. Among many other things, you can send selections or whole files to be interpreted through a REPL of your choice, including Python 3. Create Packages/User/SublimeREPL/config/Python/Main.sublime-menu
with the following contents:
[
{
"id": "tools",
"children":
[{
"caption": "SublimeREPL",
"mnemonic": "r",
"id": "SublimeREPL",
"children":
[
{"caption": "Python",
"id": "Python",
"children":[
{"command": "repl_open",
"caption": "Python 3",
"id": "repl_python3",
"mnemonic": "p",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["python3", "-i", "-u"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
}
]
}
]
}]
}
]
changing the "cmd"
option to the full path to your python3
binary. This way your changes will survive any SublimeREPL upgrades. BTW, this path works for any package, so you can feel free to customize away without fear of accidentally losing it all.
回答2:
Cmd+` is supposed to open Sublime Text's embedded interpreter console, i.e. the one that you use when developing or debugging Sublime plug-ins. You can verify that by noticing that the sublime
module is available.
If you really want Python 3 console there, upgrade to Sublime Text 3 which embeds Python 3.3. Alternatively, use a dedicated plug-in like SublimeREPL (see @MattDMo's answer).
And BTW: If you want a nice environment for interactive Python work, I suggest to disregard the above and give IPython Notebook a shot.
回答3:
You could try setting the environment variables something similar to the following in Tools > Build System > New Build System
{
"path": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
"env":
{
"PYTHONPATH":"/usr/local/lib/python:/usr/local/username/python/3.2/lib/python3.2/"
},//this comma!
"cmd": ["python3", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
回答4:
What you're seeing is the Python that comes bundled with Sublime Text. I wouldn't upgrade it, but if you want to use your own you could do something like:
ln -s $HOME/.pythonbrew/pythons/Python-2.6/lib/python2.6 /Your_Sublime_Install_Path/lib/python2.6