Sublime Forum

ImportError: No module named sublimeplugin


I just installed the Mac OSX Alpha and wanted to get started trying to write a plugin but i’m getting this error in my console whenever I save anything after importing sublimeplugin
“ImportError: No module named sublimeplugin”

Here are the contents of my file I’m doing just to test things out:

[code]import sublime, sublimeplugin

print “plugin loaded”

class Test1Command(sublimeplugin.TextCommand):
def run(self, view, args):
print “command run”[/code]

Any ideas on what I may be doing wrong or missing?



I Sublime 2, the new name’s “sublime_plugin”. That should work.



that works perfectly now, thanks!

one more question, did view.runCommand('test1') change? that’s the way the API docs specify to run it but i’m getting an AttributeError.



The api docs cover good old Sublime 1.x… Sublime 2 introduces a few changes to how the api works and looks… Most prominently, Sublime 2 api conforms to PEP8, which means camelCase becomes camel_case. However, your best bet is to dir() whatever object you’re interested in in the python console (CTRL + ~) and try to find the new names. The old docs are still valid to a great extent, but new ones are badly needed.



Ah, I see now. Well last question I promise =)

Is there a list around somewhere of good plugins that can be run on Sublime 2 that I could use as an example to look at?

Thanks again for all the help. Much appreciated.



Sublime Text 2 has only recently been released, and the API is still a little incomplete, so there aren’t a lot of plugins for it yet.
If you check out, you can see a bunch of plugins for ST1, though, and most of the calls are identical in the way that Guillermo summarized.
Feel free to keep asking questions here if you have them, though. :smile:



For example Sublime Text 2 plugins, you can have a look at the ones that ship with the editor, in the Packages/Default directory (accessible via Preferences/Browse Packages)



exactly what i needed. thanks!



Almost three years later now, and the old (Sublime 1) documents are still prominently featured on

I’m fairly new to Sublime, though I’ve been programming for decades. I have ended up wasting a couple days worth of my time, trying to figure out why I could not make any extensions work, even these simplest examples.

There is better Sublime 2 plugin documentation at … -2-plugin/

Is there --any-- way that we could get the page to mention or mention this present thread or mention that those examples are applicable only to Sublime 1 or – something – to give the poor saps who get lost trying to follow those plugin-examples a bit of a clue?

(I realize that you are almost certainly not the one to ask this question of … but I don’t know who is … perhaps I’ll get lucky and someone will offer a clue as to who might be.)

Here are the two fixes I found were needed in

  • Wrong sublimeplugin.TextCommand
    Right sublime_plugin.TextCommand

  • Wrong view.runCommand(‘hello’)
    Right view.run_command(‘hello’)

With these two fixes, the HelloCommand runs as ‘hello’ in both sublime 2 and 3, using the command:


in the console (accessible via Ctrl+~).

Someone must have edit access to that page



The API documentation at

A naive user (well, at least this naive user) might think that (based both on what the URL and the page state) is the (one and only) API for Sublime.

I would suggest that instead, a short page, with essentially just three links, to

Once again, however, I have no clue to whom to properly address these comments.



It is aggravating that the examples are not even close to working with ST v3. Here is the working version of the “Events” example. Hopefully this will save someone from experiencing my two hours of frustration:

import sublime, sublime_plugin

class EventDump(sublime_plugin.EventListener):
    def on_load(self, view):
        print (view.file_name(), "just got loaded")

    def on_pre_save(self, view):
        print (view.file_name(), "is about to be saved")

    def on_post_save(self, view):
        print (view.file_name(), "just got saved")
    def on_new(self, view):
        print ("new file")

    def on_modified(self, view):
        print (view.file_name(), "modified")

    def on_activated(self, view):
        print (view.file_name(), "is now the active view")

    def on_close(self, view):
        print (view.file_name(), "is no more")

    def on_clone(self, view):
        print (view.file_name(), "just got cloned")