Sublime Forum

How to sep up python3 as default syntax in Sublime Text 3

#1

I saved file default_syntax.py into
Library⁩ ▸ ⁨Application Support⁩ ▸ ⁨Sublime Text 3⁩ ▸ ⁨Packages⁩ ▸ ⁨User⁩
with this code in it
import sublime
import sublime_plugin
class DefaultSyntaxCommand(sublime_plugin.EventListener):
def on_new(self, view):
view.set_syntax_file(‘Packages//.tmLanguage’)

But it didn’t work.Console Panel in ST3 gives me this

Traceback (most recent call last):
File “/Users/username/Library/Application Support/Sublime Text 3/Packages/User/default_syntax.py”, line 1, in
import sublime
ModuleNotFoundError: No module named ‘sublime’
[Finished in 0.0s with exit code 1]
[shell_cmd: python3 -OO -u “/Users/username/Library/Application Support/Sublime Text 3/Packages/User/default_syntax.py”]
[dir: /Users/username/Library/Application Support/Sublime Text 3/Packages/User]
[path: /Library/Frameworks/Python.framework/Versions/3.8/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin]

Here is also a screenshot of my Sublime Text 3 Folder

How can i finally sep up python 3 as my def syntax?I don’t like using cmd+shift+p and then type python to change my syntax from plaint text to python3

UPD:I was trying this in both ST3 python3 file type and in os x terminal console with python interpreter turned on

0 Likes

#2

It looks like you’re trying to run your plugin using the build system. This is not how plugins work. Plugins are loaded automatically by Sublime Text. The build system is used for running external software. Plugins can’t be run as external software. You should be able to open a new file and then check the sublime console for any errors.

0 Likes

#3

Hi,i’m superbeg,so i didn’t get what you meant by ‘‘open a new file and then check the sublime console for any errors’’.Can you explain please?
By the way plugin doesn’t work,my def syntax is still plain text.What am i doing wrong apart from using build system to test plugin ?

0 Likes

#4

You can open the console with ctrl+` or under View > Show Console. Your plugin triggers when a new file is created, hence def on_new. Opening a new file will trigger your code and print out any errors in the console. You can also check the console for any errors that come from loading your plugin.

0 Likes

#5

I tried cmd+N and my console didn’t show me anything


Does it mean i saved my plugin wrong ?

0 Likes

#6

I can see in the bottom right that the syntax is set to python3. Is this not the expected behaviour of the plugin is working as desired?

0 Likes