Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

macports - Trouble setting Python version in Sublime Text2

I'm having trouble setting the build environment in Sublime Text2. I'm using Macports for Python and package installation.

My python.sublime-build file looks like this:

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

I think (from searching) that I need to modify the "cmd" line to point to the Macports version. Anyone done this successfully?

From Terminal, everything builds/runs fine, it's only Sublime Text2's build that's grabbing the system version still.

Additional info:

which python
/opt/local/bin/python

Thanks for any help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your Sublime Text 2 environment is different from your shell environment; the $PATH variable is probably not pointing to the same directories and the wrong executable is selected.

You have several options to work around that:

  1. Set a "path" option that includes /opt/local/bin need to use an absolute path for your python executable, as Sublime Text 2 doesn't share the same environment PATH variable your shell uses. Inspect echo $PATH and use that as a template:

    {
        "cmd": ["python", "-u", "$file"],
        "path": "/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/Current/bin:/Users/yourloginname/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin",
        "file_regex": "^[ ]*File "(...*?)", line ([0-9]*)",
        "selector": "source.python"
    }
    

    That'll use /bin/bash to run the command, which I think would have the same $PATH setting as your terminal.

  2. Run the command through the shell instead by setting the "shell" option:

    {
        "cmd": ["python", "-u", "$file"],
        "shell": true,
        "file_regex": "^[ ]*File "(...*?)", line ([0-9]*)",
        "selector": "source.python"
    }
    
  3. Use the full path for the python command:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...