Home/Support/Support Forum/Installing python modules?
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

Installing python modules?

0 votes
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 setup.py.

Thanks in advance,
Chris.
asked Aug 18, 2011 in Python by chrisjx New to the Community (19 points)

Please log in or register to answer this question.

7 Answers

0 votes
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?
answered Aug 18, 2011 by shahrj1988 Veteran of the Digi Community (263 points)
0 votes
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.
answered Aug 18, 2011 by chrisjx New to the Community (19 points)
0 votes
Here's a portion of the Digi Python Programmer's guide that may help:

http://www.digi.com/wiki/developer/index.php/Digi_Python_Programmer%27s_Guide#Loading_Python_Programs_onto_a_Digi_Device

The build_zip module referenced is available here:

http://www.digi.com/wiki/developer/index.php/Digi_build_zip
answered Aug 19, 2011 by DigiGuy42 Community Contributor (102 points)
0 votes
Thanks. Just what I was looking for...
answered Aug 19, 2011 by chrisjx New to the Community (19 points)
0 votes
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.
answered Aug 20, 2011 by shahrj1988 Veteran of the Digi Community (263 points)
0 votes
I'm perplexed. Please help. I have created a zip archive with the file calendar.py in it (for the purposes of understanding how this works).

#############
I then made a test.py file:

import sys, zipimport

sys.path.append("WEB/python/test.zip")

import calendar
#############

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

What am I missing? How do I load modules from a zip archive?
answered Oct 28, 2011 by mcostolo New to the Community (3 points)
0 votes
Take a look here: http://www.digi.com/wiki/developer/index.php/Using_ZIP%2C_GZIP_or_compression

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!
answered Mar 3, 2012 by lynnl Veteran of the Digi Community (1,047 points)
...