문제

I copied markdown and pygments folder to my plugin's path, and did this:

try: 
    import sys
    sys.path.append("./markdown")
    sys.path.append("./pygments")
    import markdown

except ImportError:
    self.view.insert(edit, 0, "The markdown package wasn't imported.")

And this doesn't work. What should I do?

도움이 되었습니까?

해결책

Just like any other Python program, if you put the markdown and pygments files/folders into your plugin's folder, you should be able to import them with no problem. For example, make your directory structure like so:

Packages/
    |
    |-MyPlugin/
        |
        |-my_plugin.py
        |
        |-markdown.py
        |
        |-pygments/
            |
            |-__init__.py
            |
            |- etc.

then in my_plugin.py you should be able to have:

import sublime
import sublime_plugin
import markdown
import pygments

class MyPluginCommand(sublime_plugin.TextCommand):
    # and so on...

This also makes your plugin much easier to distribute later on, as everything is self-contained. Obviously, make sure you are using Python 2.6-compatible versions of any third-party libraries.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top