-1

I cant import sublime_plugin.

This code worked yesterday: import sublime_plugin But when i came back today it doesn't work. My cmd.py file is inside Sublime Text 3\Packages\CMD. It gives me a ModuleNotFoundError. I use sublime text 3 and python 3. It also does not work from the command line.

I also tried to run it in VSCode which didn't work aswell.

Reinstalling sublime text 3 did not fix the problem. After reinstalling Sublime multiple times it now seems to work.

So the whole code i have is:

import os
import sublime_plugin

class CmdCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        os.system("cd " + self.view.file_name() + " & start cmd")

It worked on the day i put it in the folder.

from this link: How can I open command line prompt from Sublime in windows7

Edit: It doesn't work anymore.

Edit: It works now (i had the plugin set up with a context menu, which on its own works (so it opens the cmd) its just that when i put a text command file in there that it broke). Thanks for all the help

sputnick567
  • 324
  • 5
  • 12
  • How are you running the code? What exactly do you mean that "it does not work from the command line"? – mattst Jan 17 '21 at 15:56
  • i mean if i use python cmd.py it wont work as well. It worked on the day i got that code. Also the code opens a command prompt in the current directory – sputnick567 Jan 18 '21 at 07:52

2 Answers2

0

Try it in Spyder IDE, or try re installing it

-pip install sublime.

0

The only place it makes any sense to import the sublime_plugin module is in the code of a Sublime Text plugin and only the Sublime Text editor can execute one of its plugins.

It makes no sense to import the sublime_plugin module into code that will be run from the command line using a Python interpreter nor to try "to run it in VSCode".

I suggest you look at some Sublime Text plugin tutorials on the web and at the code of some simple plugins, something like the Switch View in Group plugin is quite straightforward and easy to understand. If you have the time available you could watch some of OdatNurd's Sublime Text Tutorials on YouTube.

mattst
  • 13,340
  • 4
  • 31
  • 43