Getting sublime Text 3/2 to recognize the custom folders with python files

448 Views Asked by At

My system: Ubuntu 14.04 & Python 2.7, with Sublime Text 3. I alter repeated this with Sublime Text 2, and still can't seem to get this to work.

I have a custom folders in which I have organized my files, say mobile/backend/scripts/ Now I want to import some functions from the folders in another script, say a.py

# a.py
from mobile.backend.scripts import funct1
#actual code

When I run this via IDLE/ cmd line it works , but not via sublime text. I also tried Pycharm, and it seems to have the same problem.

Traceback (most recent call last):
  File "/home/ekta/br/work/src/mobile/backend/scripts/a.py", line 26, in <module>
    from mobile.backend.scripts import funct1
ImportError: No module named mobile.backend.scripts
[Finished in 0.0s with exit code 1]
[shell_cmd: python -u "/home/ekta/br/work/src/mobile/backend/scripts/a.py"]
[dir: /home/ekta/br/work/src/mobile/backend/scripts]
[path: /usr/local/apache-maven/apache-maven-3.1.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games]

Observation: As you can see, the "path" in the debugger does not reflect the "mobile" path that is actually in my $PATH & $PYTHONPATH, and sys.path

The path as you see doesnt show up that it will detect my path set in ~/.bashrc, which is

$ echo $PATH

/usr/local/apache-maven/apache-maven-3.1.1/bin:/home/ekta/br/thirdparty/hadoop/bin:/home/ekta/br/tools/ec2/bin:/home/ekta/br/tools/elastic-mapreduce:/home/ekta/br/tools/gogrid:/usr/local/apache-maven/apache-maven-3.1.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/ekta/br/work/src/:/home/ekta/br/work/src/backend/python:/home/ekta/br/work/src/backend/build/lib:/mnt/production/dist/python:/mnt/production/mobile:/home/ekta/br/work/src/mobile::/home/ekta/br/thirdparty/hadoop/bin

Since I did not understand why this was missing the entire $PATH, I set up the path in Sublime Text3, Preferences-> Package settings-> Package Control-> Settings user as,

{   
    "installed_packages":
    [
        "Sublime Files",
        "SublimeLinter-pep257",
        "SublimeLinter-pep8",
        "SublimeLinter-pylint"
    ],
    "paths": {
        "linux":"/usr/local/apache-maven/apache-maven-3.1.1/bin:/home/ekta/br/thirdparty/hadoop/bin:/home/ekta/br/tools/ec2/bin:/home/ekta/br/tools/elastic-mapreduce:/home/ekta/br/tools/gogrid:/home/ekta/br/work/src/:/home/ekta/br/work/src/backend/python:/home/ekta/br/work/src/backend/build/lib:/mnt/production/dist/python:/mnt/production/mobile:/home/ekta/br/work/src/mobile::/usr/local/apache-maven/apache-maven-3.1.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/ekta/br/thirdparty/hadoop/bin",
        "osx": [],
        "windows": []
    }, 
    "env": {
        "PYTHONPATH":"/usr/local/lib/python:/home/ekta/br/work/src/:/home/ekta/br/work/src/backend/python:/home/ekta/br/work/src/backend/build/lib:/mnt/production/dist/python:/mnt/production/mobile:/home/ekta/br/work/src/mobile" 
    }
}

I also checked that I do have the paths in my sys.path

sys.path

['',
'/usr/local/lib/python2.7/dist-packages/prettytable-0.7.2-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/enum-0.4.4-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/time_uuid-0.1.1-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/protobuf_to_dict-0.0.5-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/protobuf-2.6.0-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/pycassa-1.11.0-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/thrift-0.9.1-py2.7-linux-i686.egg',
'/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.7-py2.7-linux-i686.egg',
'/usr/local/lib/python2.7/dist-packages/unicodecsv-0.9.4-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/xlutils-1.7.1-py2.7.egg',
'/usr/lib/python2.7/dist-packages',
'/usr/local/lib/python2.7/dist-packages/plumbum-1.4.2-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/EasyProcess-0.1.6-py2.7.egg',
'/home/ekta/br/work/src', 
'/home/ekta/br/work/src/backend/python',
'/home/ekta/br/work/src/backend/build/lib',
'/mnt/production/dist/python', 
'/mnt/production/mobile',
'/home/ekta/br/work/src/mobile', 
'/home/ekta', 
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-i386-linux-gnu', 
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old', 
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PILcompat',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.7',
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client']

From the doc , I undestand that this should "add" the paths to my PATH, refrence here-: http://sublimelinter.readthedocs.org/en/latest/troubleshooting.html#finding-a-linter-executable

My question, since this not set the path - What am I missing ? My goal is to do interactive REPL while debugging my script, since IDLE is not a good debugging interface.

--(Non Working) HACKS -- 1. I also tried this hack, by placing a file Pathway.py in /home/ekta/.config/sublime-text-3/Packages/User/ - but doesn't work either Reference - http://robdodson.me/blog/2012/05/14/hacking-the-path-variable-in-sublime-text/

import os

LOCAL = '/usr/local/bin:/usr/local/sbin:'
HOME = '/home/ekta'  

# Sublime's default path is
# /usr/bin:/bin:/usr/sbin:/sbin
os.environ['PATH'] += ':'
os.environ['PATH'] += LOCAL
print 'PATH = ' + os.environ['PATH']
  1. Inside the "Show console" in sublime Text 3, I see
import sys 
sys.path ['/opt/sublime_text', '/opt/sublime_text/python3.3.zip',/home/ekta/.config/sublime-text-3/Packages']

'''and obviously'''
import os 
os.environ['PATH'] '/usr/local/apache-maven/apache-maven-3.1.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games'

This sys.path did not have the "Users", so, I moved Pathways.py the file to /home/ekta/.config/sublime-text-3/Packages/ instead of /Packages/user/ - that did not help either.

EDIT -: Another Question : Why do I see "python3.3.zip" here ? Does Sublime text 3, not work with Python 2.7 ? sys.version in System console in Sublime Text 3 also showed up 2.7 - so is this all related ?

With Sublime Text2

Now I repeated the steps in hacks section, with Sublime Text 2, after unistalling Sublime Text 3 - and printed sys.path from within the file, I am trying to execute with Cntr+B, and still get the same error, no ImportError: No module named mobile.backend.scripts

0

There are 0 best solutions below