Web2PY not importing global modules

716 views
Skip to first unread message

Darin Williams

unread,
Jun 8, 2017, 5:06:38 PM6/8/17
to web2py-users
I am using Web2PY version 2.14.6 on a Mac OS X. I have installed jsonrpc and pyeapi modules using pip and they are located in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ folder. I can use import os without any issues but when I try to import jsonrpc or pyeapi, it gives the error that it cannot import the module. I can run command line code and import the modules, so not a permissions thing. Any help would be appreciated.

Version

web2py™Version 2.14.6-stable+timestamp.2016.05.10.00.21.47
PythonPython 2.7.3: /Applications/web2py.app/Contents/MacOS/python (prefix: /Applications/web2py.app/Contents/Resources)

Traceback

1.
2.
3.
4.
5.
6.
Traceback (most recent call last):
File "/Applications/web2py.app/Contents/Resources/gluon/restricted.py", line 227, in restricted
File "/Applications/web2py.app/Contents/Resources/applications/Arista_EOS_Tools/controllers/default.py", line 13, in <module>
File "/Applications/web2py.app/Contents/Resources/gluon/custom_import.py", line 89, in custom_importer
ImportError: Cannot import module 'applications.Arista_EOS_Tools.modules.jsonrpc'

Error snapshot help

<type 'exceptions.ImportError'>(Cannot import module 'applications.Arista_EOS_Tools.modules.jsonrpc')

inspect attributes

Frames

  • File /Applications/web2py.app/Contents/Resources/gluon/restricted.py in restricted at line 227 code arguments variables

  • File /Applications/web2py.app/Contents/Resources/gluon/custom_import.py in custom_importer at line 89 code arguments variables

    Function argument list

    (name='jsonrpc', globals={'A': <class 'gluon.html.A'>, 'ANY_OF': <class 'gluon.validators.ANY_OF'>, 'ASSIGNJS': <function ASSIGNJS>, 'AppConfig': <function AppConfig>, 'Auth': <class 'gluon.tools.Auth'>, 'B': <class 'gluon.html.B'>, 'BEAUTIFY': <class 'gluon.html.BEAUTIFY'>, 'BODY': <class 'gluon.html.BODY'>, 'BR': <class 'gluon.html.BR'>, 'BUTTON': <class 'gluon.html.BUTTON'>, ...}, locals={'A': <class 'gluon.html.A'>, 'ANY_OF': <class 'gluon.validators.ANY_OF'>, 'ASSIGNJS': <function ASSIGNJS>, 'AppConfig': <function AppConfig>, 'Auth': <class 'gluon.tools.Auth'>, 'B': <class 'gluon.html.B'>, 'BEAUTIFY': <class 'gluon.html.BEAUTIFY'>, 'BODY': <class 'gluon.html.BODY'>, 'BR': <class 'gluon.html.BR'>, 'BUTTON': <class 'gluon.html.BUTTON'>, ...}, fromlist=[], level=-1)

    Code listing
    84.
    85.
    86.
    87.
    88.
    89.

    90.
    91.
    92.
    93.
                            new_mod = base_importer(
    modules_prefix, globals, locals, [itemname], level)
    try:
    result = result or sys.modules[modules_prefix+'.'+itemname]
    except KeyError, e:
    raise ImportError, 'Cannot import module %s' % str(e)

    modules_prefix += "." + itemname
    return result
    else:
    # import like "from x import a, b, ..."
    Variables

In file: /Applications/web2py.app/Contents/Resources/applications/Arista_EOS_Tools/controllers/default.py

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
# -*- coding: utf-8 -*-
# this file is released under public domain and you can use without limitations

# -------------------------------------------------------------------------
# This is a sample controller
# - index is the default action of any application
# - user is required for authentication and authorization
# - download is for downloading files uploaded in the db (does streaming)
# -------------------------------------------------------------------------

import os
print (os.environ['PYTHONPATH'])
import jsonrpc
import pyeapi
def index():
"""
example action using the internationalization operator T and flash
rendered by views/default/index.html or views/generic.html

if you need a simple wiki simply replace the two lines below with:
return auth.wiki()
"""

return dict(message=T('Arista EOS Tools'))

def add_inventory():
form = SQLFORM.factory(
Field('username', requires=IS_NOT_EMPTY()),
Field('password', 'password', requires=IS_NOT_EMPTY()),
Field('switchip', 'text', label="Switch IPs"))

return dict(form=form)

response._vars=response._caller(add_inventory)
 

Anthony

unread,
Jun 8, 2017, 5:17:46 PM6/8/17
to web2py-users
Looks like you are using the OSX binary web2py, which includes its own Python interpreter and doesn't see anything in your system installation of Python. Instead, just use the source version of web2py -- binary is only needed if you don't have Python installed.

Anthony

Darin Williams

unread,
Jun 9, 2017, 5:04:59 PM6/9/17
to web2py-users
That fixed the issue.
Reply all
Reply to author
Forward
0 new messages