pythonsublimetext3sublime-text-pluginsublime-anaconda

Anaconda ignoring "extra_paths" in Sublime Text settings


I'm trying to configure Sublime Text 3 to act as my IDE for Python development, and while I've read the documentation, I'm still having problems importing extra libraries using the Anaconda.sublime-settings file. From what I've read, it should be as simple as having this text in the Anaconda.sublime-settings file:

{
    "python_interpreter": "/Users/mc/anaconda/bin/python",
    "extra_paths":
    [
    "/Users/mc/workspaces/brg/brg_framework/libs/python",
    "/Users/mc/workspaces/brg/brg_packages/brg_fea"
    ]
}

When I try to build a file, I immediately get an ImportError about a module from that python library (brg is a folder in the ~/brg_framework/libs/python package). If I ask for the paths for the build, I get the following, but not my extra path.

print sys.path
['/Users/mc/workspaces/BRG/brg_packages/brg_splines', '/Users/mc/anaconda/lib/python27.zip', '/Users/mc/anaconda/lib/python2.7', '/Users/mc/anaconda/lib/python2.7/plat-darwin', '/Users/mc/anaconda/lib/python2.7/plat-mac', '/Users/mc/anaconda/lib/python2.7/plat-mac/lib-scriptpackages', '/Users/mc/anaconda/lib/python2.7/lib-tk', '/Users/mc/anaconda/lib/python2.7/lib-old', '/Users/mc/anaconda/lib/python2.7/lib-dynload', '/Users/mc/anaconda/lib/python2.7/site-packages', '/Users/mc/anaconda/lib/python2.7/site-packages/Sphinx-1.3.5-py2.7.egg', '/Users/mc/anaconda/lib/python2.7/site-packages/aeosa', '/Users/mc/anaconda/lib/python2.7/site-packages/setuptools-21.2.1-py2.7.egg']

ImportError: No module named brg.datastructures.network.network
[Finished in 0.0s with exit code 1]
[shell_cmd: python -u "/Users/mc/workspaces/BRG/brg_packages/brg_splines/splinenetwork.py"]
[dir: /Users/mc/workspaces/BRG/brg_packages/brg_splines]
[path: /Users/mc/anaconda/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/TeX/texbin]

Is the Anaconda.sublime-settings file being overridden somehow? I am running OS X if that matters.


Solution

  • As r-stein indicated, the "extra_paths" setting in Anaconda is for its auto-completing and linting features, not for building. If you need to change your PYTHONPATH, you'll have to create a new build system. Select Tools → Build System → New Build System…, erase the contents of the view that opens, and add this instead:

    {
        "shell_cmd": "/Users/mc/anaconda/bin/python -u \"$file\"",
        "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
        "selector": "source.python",
        "env": {"PYTHONPATH": "/Users/mc/workspaces/brg/brg_framework/libs/python:/Users/mc/workspaces/brg/brg_packages/brg_fea"}
    }
    

    Save the file as Packages/User/brg_Python.sublime-build (the Save dialog should already open in Packages/User. Now, you can select Tools → Build System → brg_Python and run your program with B.