Sublime Forum

ImportError: No module named sublimeplugin

#1

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?

0 Likes

#2

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

0 Likes

#3

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.

0 Likes

#4

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.

0 Likes

#5

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.

0 Likes

#6

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 sublimetext.info/, 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:

0 Likes

#7

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)

0 Likes

#8

exactly what i needed. thanks!

0 Likes

#9

Almost three years later now, and the old (Sublime 1) documents are still prominently featured on sublimetext.com/docs/plugin-examples.

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 net.tutsplus.com/tutorials/pytho … -2-plugin/

Is there --any-- way that we could get the http://www.sublimetext.com/docs/plugin-examples page to mention http://net.tutsplus.com/tutorials/python-tutorials/how-to-create-a-sublime-text-2-plugin/ 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 http://www.sublimetext.com/docs/plugin-examples.

  • 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:

view.runCommand('hello') 

in the console (accessible via Ctrl+~).

Someone must have edit access to that http://www.sublimetext.com/docs/plugin-examples page

0 Likes

#10

The API documentation at sublimetext.com/docs/3/api_reference.html.

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

I would suggest that instead sublimetext.com/docs/api-reference, a short page, with essentially just three links, to

sublimetext.com/docs/1/api-reference
sublimetext.com/docs/2/api-reference
sublimetext.com/docs/3/api-reference

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

0 Likes

#11

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")
0 Likes