Home Download Buy Blog Forum Support

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

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

Postby gregor.hoch on Sat Aug 10, 2013 1:38 am

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!
gregor.hoch
 
Posts: 144
Joined: Sat Oct 01, 2011 7:54 pm

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

Postby sapphirehamster on Sat Aug 10, 2013 11:11 pm

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

Code: Select all
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).
sapphirehamster
 
Posts: 88
Joined: Sun Jul 01, 2012 11:19 pm


Return to Plugin Development

Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests