Directing Sublime Text 2 Packages to the correct p

2019-01-17 08:38发布

问题:

I just want to direct a Sublime Text 2 Package (SublimeREPL) to the correct python installation--at the moment, it's picking up the wrong one.

The story here is familiar to Mac users. The Mac OS comes includes a python install which it uses for various OS stuff for which python is required. Like many others, i prefer not to use this system python (which resides in /System/Library/...) becasue it is usually out of date and of course it's not a good idea to update it--it is a working python install used by the Mac OS, and updating risks causing those OS tasks that depend on that install to break.

But that's the version picked up by the package SublimeREPL:

Python 2.7.1 (r271:86832, Jun 25 2011, 05:09:01) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

The version i use for development (and which is installed in /Library/Frameworks/ and symlinked to /usr/local/bin) is:

@ > python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:52:43) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Sublime 2 Text is picking up the correct version elsewhere, except when using the SublimeREPL Package so there must be a setting in one of the config files in that Package that will let me direct SublimeREPL to the correct python.

But i can't find it.

It seems that i have exhausted all plausible options, which, looking through my /Sublime Text 2/Packages/ directory must reside in either:

SublimeREPL/

    SublimeREPL (OSX).sublime-settings
    SublimeREPL.sublime-settings

Or

User/

    SublimeREPL.sublime-settings

In fact, i added the following each of the three JSON files above, with no effect:

{
    "default_extend_env": {"PATH": "/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin/python2.7:{PATH}"}
}

回答1:

If you want to use repl_open you could edit the cmd parameter in the config. I am using Ubuntu and it is located in:

/home/stav/.config/sublime-text-2/Packages/SublimeREPL/config/Python/Main.sublime-menu

{"command": "repl_open",
"caption": "Python",
"id": "repl_python",
"mnemonic": "p",
"args": {
  "type": "subprocess",
  "encoding": "utf8",
  "cmd": ["/usr/local/bin/python", "-i", "-u"],
  "cwd": "$file_path",
  "syntax": "Packages/Python/Python.tmLanguage",
  "external_id": "python"
  }
},


回答2:

@Steven Almeroth solution did not work for me.

Instead a changed a parameter in the following directory: packages/Python/Python.sublime-build

The following code is available there. Simple change the cmd to the directory where your brew of python is located.

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


回答3:

From my experience it's simpler to fix a mess around versions patching environment variables specifically for Sublime Text 2 process

The only straight and dumb solution I've found - hack environment variables for Sublime Text 2. This can be done creating .py file with any name in folder:

~/Library/Application Support/Sublime Text 2/Packages/User/

Just add paths you need there and all plugins will use those settings. See more information in Rob Dodson's blog post: http://robdodson.me/blog/2012/05/14/hacking-the-path-variable-in-sublime-text/

Example .py:

import os

LOCAL = '/usr/local/bin:/usr/local/sbin:'

# Sublime's default path is
# /usr/bin:/bin:/usr/sbin:/sbin
os.environ['PATH'] += ':'
os.environ['PATH'] += LOCAL

print 'PATH = ' + os.environ['PATH']