Installing python modules?

Has anyone seen documentation about the python modules available within the Connectport devices? (I’m using an X2)

I need to “import urllib, urllib2, httplib” and maybe a suds (SOAP) module.

In my current setup if I just try to import urllib I get an error message indicating that it can’t be found.

Also, is there a process for adding a custom module? In my previous environment I would load the module components into a sub-directory and then run python

Thanks in advance,

You can make the .zip file of the compiled python library files and then import the modules from the zip archieve by adding the zip archieve path to sys.path.

Is that make sense?

Great tip. I think I saw a reference to this approach but have since been unable to find again.

So besides including the files associated with the module into the zip, I would need to compile them first (into .pyc files). Is there a particular compile trick/version, etc. I am working in Windows Vista with installed version of python 2.7.2. I use Notepad++ to edit scripts.

Thanks for your help, Shahrj.

Here’s a portion of the Digi Python Programmer’s guide that may help:'s_Guide#Loading_Python_Programs_onto_a_Digi_Device

The build_zip module referenced is available here:

Thanks. Just what I was looking for…

To use the compiled python files on ConnectPort X2, you need to install python 2.4.3 and then compile all the files in the folder by using ‘compileall’ module using python 2.4.3 IDLE.

I’m perplexed. Please help. I have created a zip archive with the file in it (for the purposes of understanding how this works).

I then made a file:

import sys, zipimport


import calendar

They are both uploaded to the X2. I get “Traceback (most recent call last):
File “”, line 5, in ?
ImportError: No module named calendar”

What am I missing? How do I load modules from a zip archive?

Take a look here:

Make sure you didn’t include a path within the ZIP file - so it might be “import test.calender” if within your ZIP you have a test directory.

As for the comment about PY vs PYC, you can upload either. The PYC is faster, and often smaller - but not always!