Sublime Forum

ST3 and importing of external python libraries (e.g. Crypto)

#1

Hi,

I am trying to import different python libraries which I add to my package folder like this /Packages/MyPackage/Crypto. To make this work, however, I have to change a lot of the import command in the library itself. Here is an example from the file ‘/Crypto/Random/OSRNG/rng_base.py’ in the Crypto library. This does not work in ST3
from rng_base import BaseRNG
instead, I have to use
from MyPackage.Crypto.Random.OSRNG.rng_base import BaseRNG
which seems ridicules particularly because i have to do this for all the import commands in the library I want to add (of course not import os etc)

Any other approach or better solution? I think this was not required in ST2.

Thanks!

0 Likes

#2

AFAIK, there is not a very clean solution to this. I have noticed most plugin authors are doing something similar to:

import os
import sys

sys.path.insert(0, os.path.dirname(__file__))

near the beginning of your package’s top-level file (such as Packages/MyPackage/my_package.py).

0 Likes