Search code examples
web2pyweb2py-modules

Web2py: <type 'exceptions.ImportError'> (ImportError("Cannot import module 'applications.*.modules.paramiko'",)


I believe this problem has been addressed in various forums and in here also. And the acceptable solution seems to be using source version of web2py. And I am using it. I had setup web2py on my ubuntu machine by running the setup-web2py-ubuntu.sh .

Version

2.15.4-stable+timestamp.2017.09.02.04.02.22
(Running on Apache/2.4.18 (Ubuntu), Python 2.7.12)

But when i try to load my application, which uses paramiko and load of other python libraries, I get this error. Kindly help.

Traceback (most recent call last):
  File "/home/www-data/web2py/gluon/restricted.py", line 219, in restricted
    exec(ccode, environment)
  File "/home/www-data/web2py/applications/rip/models/scheduler.py", line 3, in <module>
    import paramiko
  File "/home/www-data/web2py/gluon/custom_import.py", line 104, in custom_importer
    raise ImportError(e1, import_tb)  # there an import error in the module
ImportError: (ImportError("Cannot import module 'applications.rip.modules.paramiko'",), <traceback object at 0xac07eb6c>)

P.S: rip is my application name.


Solution

  • After going through the books, I came to know that we have to have the python libraries in the web2py modules directory.

    sudo pip install paramiko --target /home/www-data/web2py/applications/<your_application_name>/modules
    

    In case you want to install ANy package to that directory, which by default would have landed to site-packages, you can do this.

    python setup.py install --prefix=/home/www-data/web2py/applications/<your_application>/modules
    

    This worked for me perfectly.