Sublime Forum

How to 'import sublime' in PyCharm

#1

I’m trying to write a plugin in pycharm.
The main problem is that when i have `import sublime’ i cant run the file - this is especially problematic for UT.
I get this error

File “C:/Users/…my_plugin…/utils/brudnopis.py”, line 57, in
import sublime
File “C:\Program Files\Sublime Text 3\sublime.py”, line 3, in
import sublime_api
ImportError: No module named ‘sublime_api’

As you can see i managed to make PyCharm see the ‘sublime’ and ‘sublime_module’ modules but no further…

help, notice me senpai

0 Likes

#2

You cannot run Sublime Text plugins outside the Sublime Text environment.

1 Like

#3

I’m not trying to run them.
I’m trying to ‘import sublime’ for it’s types and typenames to unit-test my plugin: functions, utils, classes, etc.

0 Likes

#4

The sublime_api module is embedded in the Sublime executable itself, it’s not something that’s externally visible.

>>> import sys, sublime_api
>>> sys.modules["sublime_api"]
<module 'sublime_api' (built-in)>

As such, the only Python interpreter capable of importing that module is the one that’s embedded in Sublime. I imagine the best that you’re going to be able to do is define your own dummy sublime_api module elsewhere.

1 Like

#5

I should create some type stubs for the ST modules. Been wanting to do that for a while, but I’m unsure about distribution. I wonder if typeshed would accept them.

1 Like