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.

Answers


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"
    }
    

Need Your Help

Zend AMF and Flash Tutorials

php flash zend-amf

I'm trying to learn Zend AMF but with Flash instead of Flex. I've seen Lee Brimelow's introduction tut, but are there any others out there that cover things more in depth?

Java Getting String from another class returning null

java string null

I currently have two constructors in one of my classes, one going to my main class, and the other to another class that has most of the methods that I use. The reason I don't use static methods for...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.