# Installing python modules?

**URL:** <https://forums.digi.com/t/installing-python-modules/2805>\
**Category:** Python\
**Created:** [August 18, 2011, 5:30pm UTC](https://forums.digi.com/t/installing-python-modules/2805 "2011-08-18T17:30:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisjx](https://avatars.discourse-cdn.com/v4/letter/c/8e8cbc/32.png) [@chrisjx](https://forums.digi.com/u/chrisjx)\
**Post date:** [August 18, 2011, 5:30pm UTC](https://forums.digi.com/t/installing-python-modules/2805/1 "2011-08-18T17:30:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![shahrj1988](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@shahrj1988](https://forums.digi.com/u/shahrj1988)\
**Post date:** [August 18, 2011, 8:13pm UTC](https://forums.digi.com/t/installing-python-modules/2805/2 "2011-08-18T20:13:11Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![chrisjx](https://avatars.discourse-cdn.com/v4/letter/c/8e8cbc/32.png) [@chrisjx](https://forums.digi.com/u/chrisjx)\
**Post date:** [August 18, 2011, 11:16pm UTC](https://forums.digi.com/t/installing-python-modules/2805/3 "2011-08-18T23:16:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DigiGuy42](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@DigiGuy42](https://forums.digi.com/u/DigiGuy42)\
**Post date:** [August 19, 2011, 7:34pm UTC](https://forums.digi.com/t/installing-python-modules/2805/4 "2011-08-19T19:34:03Z")

</div>

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's\_Guide#Loading\_Python\_Programs\_onto\_a\_Digi\_Device](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](http://www.digi.com/wiki/developer/index.php/Digi_build_zip)

---

<div class="post-metadata">

**Author:** ![chrisjx](https://avatars.discourse-cdn.com/v4/letter/c/8e8cbc/32.png) [@chrisjx](https://forums.digi.com/u/chrisjx)\
**Post date:** [August 19, 2011, 10:10pm UTC](https://forums.digi.com/t/installing-python-modules/2805/5 "2011-08-19T22:10:44Z")

</div>

Thanks. Just what I was looking for…

---

<div class="post-metadata">

**Author:** ![shahrj1988](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@shahrj1988](https://forums.digi.com/u/shahrj1988)\
**Post date:** [August 20, 2011, 12:08pm UTC](https://forums.digi.com/t/installing-python-modules/2805/6 "2011-08-20T12:08:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mcostolo](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mcostolo](https://forums.digi.com/u/mcostolo)\
**Post date:** [October 28, 2011, 5:13pm UTC](https://forums.digi.com/t/installing-python-modules/2805/7 "2011-10-28T17:13:37Z")

</div>

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 “”, line 5, in ?  
ImportError: No module named calendar”

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

---

<div class="post-metadata">

**Author:** ![lynnl](https://avatars.discourse-cdn.com/v4/letter/l/22d042/32.png) [@lynnl](https://forums.digi.com/u/lynnl)\
**Post date:** [March 3, 2012, 1:37am UTC](https://forums.digi.com/t/installing-python-modules/2805/8 "2012-03-03T01:37:37Z")

</div>

Take a look here: [http://www.digi.com/wiki/developer/index.php/Using\_ZIP%2C\_GZIP\_or\_compression](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!
