Sublime Forum

Sublime text path is wrong

#1

Hello, I am trying to use sublime text 3 to run python3 but whenever I press build and there is a module in the code it says that the module isn’t installed even thought I know for sure that is. In the bottom where it says the error it also says the dir. and the path I check and the path it has is incorrect it says

[path: /Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/opt/X11/bin]

but my correct path where all my modules are installed are:

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages

the sublime text lets me delete that path and change it but when I try and run the script again it changes back to that path and gives me the no module installed error again. Please help me.

0 Likes

Incorrect python path
#2

The PATH is the location that the OS searches for binaries and programs when you execute them. As such, it doesn’t matter if your Python lib folder is contained in it or not.

Are you sure you’re running python3? You might try running something like the following to verify that the correct version of Python is being executed by your build.

import sys
print(sys.version)
0 Likes

#3

Thanks for the response, I ran the code and it says 2.7.10. How would I change it to 3?

2.7.10 (default, Oct 6 2017, 22:29:07)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)]
[Finished in 0.0s] to be exact

0 Likes

#4

The command that gets executed is stored in the sublime-build that you’re using. If you have created a customized one, you can swap python to python3 in it to invoke the version of Python that you intended.

If you’re not using a custom build, probably the easiest solution would be to select Tools > Build System > New Build System... from the menu, which will open up a buffer with a stub build in it. Once you’ve done that, replace the entire contents with the following and then save it in the location that Sublime will default to (your User folder) with a name like Python3.sublime-build:

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

    "env": {"PYTHONIOENCODING": "utf-8"},

    "variants":
    [
        {
            "name": "Syntax Check",
            "shell_cmd": "python3 -m py_compile \"${file}\"",
        }
    ]
}

This represents what the built in Python build system looks like with the appropriate changes. Once you’ve done that, you want to either select Python3 from Tools > Build System (it will appear in the menu with the same name as the file), or alternatively set the build to Automatic.

If you go the second route, the next time you build Sublime should open a panel to ask you select which build you want to use; from there select Python3 to build using this build system and Python to use the built in version (Python 2). You can also get Sublime to prompt you by selecting Tools > Build With... from the menu or by pressing the appropriate key, should you want to switch back and forth.

1 Like

#5

Thank you it worked

0 Likes