OpenWrt Forum Archive

Topic: Python: No modules named "cgi" or "io"

The content of this topic has been archived on 22 Mar 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I have an Arduino with an IR LED hooked up to a WR703N (with extroot) via a CP2102 USB to UART bridge. I'm trying to recreate the project documented at http://www.righto.com/2009/11/controlli … -with.html in which the click of a button on a web page results in an IR LED blinking out remote control codes for e.g. a TV, amplifier etc.

The WR703N is running OpenWrt trunk as of 2015-03-11 (Chaos Calmer Bleeding Edge, r44634) and I'm locally hosting the package repository built at the time I generated my image. My issue is with Python.

After some initial difficulties with file clashes between various Python packages I was able to install Python with this:

opkg install python python-pip --force-overwrite

At this point I assume everything is installed OK (Python version is 2.7), but I'm not sure how to confirm other than confirming that something happens with:

python -h

My issue arises when I try to run the server.py script found at the above URL, which imports the "cgi" module; this doesn't exist and so I get the error:

ImportError: No module named cgi

Upon attempting to install the cgi module via either:

easy_install cgi

or:

pip install cgi

I get the error

ImportError: No module named io

As such I've hit a bit of a roadblock and my Google-fu has thus far proved inadequate.


My questions are:

  1. Is it possible to install the "io" module? If so, how?

  2. What is the best way (assuming it's possible) to install Python modules such as "cgi" in OpenWrt?

Any help is greatly appreciated. Apologies for the tenuous "hardware hacking" connection here; I couldn't see a more suitable forum.

Thanks.

As far as I know, the io module should be in there with Python.
If not, I should look into fixing it.

commodo wrote:

As far as I know, the io module should be in there with Python.
If not, I should look into fixing it.

Running this:

python
>>> import sys
>>> sys.builtin_module_names

Gives this result:

('__builtin__', '__main__', '_ast', '_codecs', '_sre', '_symtable', '_warnings', '_weakref', 'errno', 'exceptions', 'gc', 'imp', 'marshal', 'posix', 'pwd', 'signal', 'sys', 'thread', 'xxsubtype', 'zipimport', 'zlib')

I get the same built-in packages as you.

This works

root@OpenWrt:/# python
Python 2.7.9 (default, May 10 2015, 08:40:13) 
[GCC 4.8.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import io
>>>

And

pip install cgi

will run out of memory.

I'll come back when I re-create an image that can run this:

root@OpenWrt:/# df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                   46.5M     31.0M     14.6M  68% /
/dev/root                46.5M     31.0M     14.6M  68% /
tmpfs                   122.6M     52.0K    122.5M   0% /tmp
tmpfs                   512.0K         0    512.0K   0% /dev

OpenWRT on x86_64 VM seems to require a bit more RAM (i.e 512 MB).

Got this:

root@OpenWrt:/# pip install cgi
Downloading/unpacking cgi
  Could not find any downloads that satisfy the requirement cgi
Cleaning up...
No distributions at all found for cgi
Storing debug log for failure in /root/.pip/pip.log

The discussion might have continued from here.