Sublime Forum

ST3 import python library

#1

Hi,

I want to use the jinja2 python library for my new plugin. But I can’t get it to work to import it in my main plugin file.

MyPlugin/
jinja2/
MyPlugin.py

Already tried that:
dist_dir = os.path.dirname(os.path.abspath(file))
sys.path.insert(0, dist_dir)

Any ideas how to get that working?

Thank you
Philipp

0 Likes

#2

It would be really helpful if you posted the actual error message you were getting.

If I had to guess, do you also have the “markupsafe” directory (a dependency of jinja2) in your plugin’s directory? Sometimes python’s import error messages can be confusing.

0 Likes

#3

Thank you for your reply. The error message looks like:

File “…/Library/Application Support/Sublime Text 3/Packages/MyPlugin/MyPlugin.py”, line 10, in
from jinja2 import Environemnt, FileSystemLoader
File “…/Library/Application Support/Sublime Text 3/Packages/MyPlugin/jinja2/init.py”, line 33, in
from jinja2.environment import Environment, Template
File “…/Library/Application Support/Sublime Text 3/Packages/MyPlugin/jinja2/environment.py”, line 13, in
from jinja2 import nodes
ImportError: cannot import name nodes

Haven’t “markupsafe” in my plugin directory yet…

Thanks

0 Likes

#4

Indeed it was the missing “markupsafe” package…

Thanks!

0 Likes