Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime Text 2 & PYTHONPATH

When running a python script on Sublime Text 2 (OSX), the python interpreter works (using Enthought Python Distribution) but not my own PYTHONPATH. Here's what the Python.sublime-build file looks like at the moment:

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

How can I add the PYTHONPATH to this file correctly? I know that the PYTHONPATH is not being picked up by Sublime Text 2, since some of my custom packages cannot be imported. Any help would be greatly appreciated.

Cheers

like image 497
ebressert Avatar asked Sep 10 '11 20:09

ebressert


2 Answers

I'm working with SublimeText2 build 2202 (I have a license and I can download all the "nightly" releases) and I add an "env" attribute to the builder.

For example:

{
    "path": "/Library/Frameworks/EPD64.framework/Versions/Current/bin/",
    "cmd": ["python2.7", "-u", "$file"],
    "env":
    {
        "PYTHONPATH": "path/to/a/folder:path/to/another/folder",
    },    
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python"
}

Whatever values you set in this way will be prepended to the PYTHONPATH that Sublime sees.

Your problem was a little different, but I thought that knowing this could be helpful.

like image 135
Dan Niero Avatar answered Sep 28 '22 12:09

Dan Niero


In my mac, I need to add a comma after the back brace of "env"

{
    "path": "/Library/Frameworks/EPD64.framework/Versions/Current/bin/",
    "cmd": ["python2.7", "-u", "$file"],
    "env":
    {
        "PYTHONPATH": "path/to/a/folder:path/to/another/folder",
    },    
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python"
}
like image 27
Russj Avatar answered Sep 28 '22 12:09

Russj