Sublime Forum

Using paramiko library in ST2 plugins

#1

EDIT: SOLUTION IS BELOW

Hi,

I am not able to load the Crypto library in ST2 (Mac OS X). I know that “Sublime Text ships with a trimmed down standard library. Notable missing modules are the Tkinter, multiprocessing and sqlite3 modules. trimmed down standard library. Notable missing modules are the Tkinter, multiprocessing and sqlite3 modules.” (docs.sublimetext.info/en/latest/ … ugins.html)

But this list does not include Crypto and my understanding is that ST2 on Mac OX is using system python (I can, for example, import sqlite3).

Any ideas?

Thanks!

ps: I actually want to use paramiko, which relies on Crypto.

0 Likes

#2

Crypto is not a built-in python module. It is a 3rd party package. You can check the Python documentation, there is no crypto.

This is from a python install on the MAC (not from ST2).

>>> import crypto Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named crypto

0 Likes

#3

Yes, of course, you are right! So what I did is get the files from the paramiko library, copy them to the folder [ST Packages]/[MY PACKAGE]/paramiko with the init in it and I should be able to load the library, right? I am still failing with the Crypto library. It’s actually in a subfolder of the paramiko library so I copy it from this subfolder to [ST Packages]/[MY PACKAGE]/Crypto, which solves one problem but others come up. The one I am currently stuck with is this:
File “./Crypto/Util/Counter.py”, line 59, in
from Crypto.Util import _counter

Any ideas?

EDIT: Actually, I downloaded crypto separately and placed it in the [ST Packages]/[MY PACKAGE]/Crypto folder. Here are the two links:
lag.net/paramiko/download/pa … .7.7.1.zip
dlitz.net/software/pycrypto/
Then I get the error
File “./Crypto/Random/init.py”, line 28, in
from Crypto.Random import OSRNG
which is solved by changing line 28 in the Crypto/Random/init.py file from ‘from Crypto.Random import OSRNG’ to ‘import OSRNG’ Now I arrive at the error
File “./Crypto/Util/Counter.py”, line 59, in
import _counter

Any solutions? Am I doing something wrong when I try to ‘install’ a library for ST2 python?

0 Likes

#4

okay, I solved my problem. Here are the steps just in case anyone else wants to use the ‘paramiko’ library for a ST2 plugin:

  1. use ‘easy_install paramiko’ to install paramiko and crypto. Now your system python should be able to import paramiko
  2. Install paramiko for your ST2 plugin
    a) Get paramiko from here lag.net/paramiko/ (or alternatively the most recent version from github).
    b) Place the folder with the ‘init.py’ file in [ST Packages]/[MY PACKAGE]/paramiko
  3. Install Crypto for your ST2 plugin
    a) Check where your python libraries are using
    python -c “from distutils.sysconfig import get_python_lib; print get_python_lib()”
    b) Go to that folder (in my case /Library/Python/2.7/site-packages) and copy the file ‘pycrypto-2.6-py2.7-macosx-10.8-intel.egg’ somewhere
    c) Unpack it (just rename it to .zip)
    d) copy the Crypto folder with the init file from the unpacked folder to [ST Packages]/[MY PACKAGE]/Crypto
  4. Change line 28 in the file ‘…/Crypto/Random/init.py’ from ‘Crypto.Random import OSRNG’ to ‘import OSRNG’
    (Note: I think you have to go through the installed Crypto package and not just the downloaded one because that includes some compiled c libraries. So I guess you can also compile them yourself)

I know, it’s a mess but now you should be ready to go. If anyone has an easier solution, please post. I think that these kind of things prevent a lot of non-professional developers from developing packages.

0 Likes

Importing paramiko (& other libraries)