Home Download Buy Blog Forum Support

Using paramiko library in ST2 plugins

Using paramiko library in ST2 plugins

Postby gregor.hoch on Tue Nov 27, 2012 4:35 am

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." (http://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.
Last edited by gregor.hoch on Tue Nov 27, 2012 8:01 pm, edited 4 times in total.
gregor.hoch
 
Posts: 141
Joined: Sat Oct 01, 2011 7:54 pm

Re: "import Crypto" does not work in ST2's Python!?

Postby facelessuser on Tue Nov 27, 2012 5:07 am

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).
Code: Select all
>>> import crypto
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named crypto
facelessuser
 
Posts: 1543
Joined: Tue Apr 05, 2011 7:38 pm

Re: "import Crypto" does not work in ST2's Python!?

Postby gregor.hoch on Tue Nov 27, 2012 6:45 pm

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 <module>
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:
http://www.lag.net/paramiko/download/pa ... .7.7.1.zip
https://www.dlitz.net/software/pycrypto/
Then I get the error
File "./Crypto/Random/__init__.py", line 28, in <module>
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 <module>
import _counter

Any solutions? Am I doing something wrong when I try to 'install' a library for ST2 python?
gregor.hoch
 
Posts: 141
Joined: Sat Oct 01, 2011 7:54 pm

Re: Using paramiko library in ST2 plugins

Postby gregor.hoch on Tue Nov 27, 2012 8:00 pm

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 http://www.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.
gregor.hoch
 
Posts: 141
Joined: Sat Oct 01, 2011 7:54 pm


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 7 guests