I can not import module in app

178 views
Skip to first unread message

Константин Комков

unread,
May 17, 2019, 3:42:28 AM5/17/19
to web2py-users
I want import module. I create module mytest like in book, but after import I heve error. I tried to import mytest in another app and it work. What is reason of it? I tried import module like that : from applications.application.modules import mytest but error the same.

Error ticket for "application"

Ticket ID

192.168.20.177.2019-05-17.10-35-07.293afb38-6e29-461b-8ccb-46092d983b29

<type 'exceptions.ImportError'> No module named application.modules

Версия

web2py™Version 2.18.5-stable+timestamp.2019.04.08.04.22.03
PythonPython 2.7.10: C:\Python27\python.exe (prefix: C:\Python27)

Traceback

1.
2.
3.
4.
5.
6.
7.
8.
Traceback (most recent call last):
File ".\gluon\restricted.py", line 219, in restricted
exec(ccode, environment)
File "C:\inetpub\wwwroot\applications\application\controllers/default.py", line 2, in <module>
import datetime, calendar, mytest
File ".\gluon\custom_import.py", line 74, in custom_importer
modules_prefix, globals, locals, (itemname,), level)
ImportError: No module named application.modules

Leonel Câmara

unread,
May 17, 2019, 11:59:51 AM5/17/19
to web2py-users
Inside the application which has the module in its modules folder all you need is "import mytest"

Константин Комков

unread,
May 17, 2019, 5:49:45 PM5/17/19
to web...@googlegroups.com
Check line 8 in error, it already contain import mytest, in another project i can import that module. 

пт, 17 мая 2019 г., 18:59 Leonel Câmara <leonel...@gmail.com>:
Inside the application which has the module in its modules folder all you need is "import mytest"

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/vdwfLThWz0U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/dd1443ec-704f-48af-af0a-d66988d9281a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dave S

unread,
May 17, 2019, 8:38:02 PM5/17/19
to web2py-users


On Friday, May 17, 2019 at 2:49:45 PM UTC-7, Константин Комков wrote:
Check line 8 in error, it already contain import mytest, in another project i can import that module. 

The working application has a modules/_init__.py file; does the  excepting app have that?

/dps


пт, 17 мая 2019 г., 18:59 Leonel Câmara <leonel...@gmail.com>:
Inside the application which has the module in its modules folder all you need is "import mytest"

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/vdwfLThWz0U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web...@googlegroups.com.

Константин Комков

unread,
May 18, 2019, 10:05:07 AM5/18/19
to web...@googlegroups.com
Yes it have, but that file is empty

сб, 18 мая 2019 г., 3:38 Dave S <snide...@gmail.com>:
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/4a3f7f28-cf62-47eb-a1c8-ddbdc9f81a65%40googlegroups.com.

Dave S

unread,
May 20, 2019, 3:57:23 AM5/20/19
to web2py-users


On Saturday, May 18, 2019 at 7:05:07 AM UTC-7, Константин Комков wrote:
Yes it have, but that file is empty


Empty is ok, but the file is required.

/dps
 

Константин Комков

unread,
May 23, 2019, 7:03:05 AM5/23/19
to web2py-users
Maybe it info can help?

Error snapshot help

<type 'exceptions.ImportError'>(No module named application.modules)

inspect attributes

Frames

  • File C:\inetpub\wwwroot\gluon\restricted.py in restricted at line 219 код аргументы переменные

  • File C:\inetpub\wwwroot\applications\application\controllers\bak.py in <module> at line 2 код аргументы переменные

  • File C:\inetpub\wwwroot\gluon\custom_import.py in custom_importer at line 74 код аргументы переменные

    Function argument list

    (name='mytest', globals={'A': <class 'gluon.html.A'>, 'ANY_OF': <class 'pydal.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 'pydal.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=None, level=-1)

    Code listing
    69.
    70.
    71.
    72.
    73.
    74.
    75.
    76.
    77.
    78.
            if not fromlist:
    # "import x" or "import x.y"
    result = None
    for
    itemname in name.split("."):
    new_mod = base_importer(

  • modules_prefix, globals, locals, (itemname,), level)
  •                 modules_prefix += "." + itemname
    if result is None:
    try:
    result = sys.modules[modules_prefix]
    Variables
    modules_prefix'applications.application.modules'
    globals{'A': <class 'gluon.html.A'>, 'ANY_OF': <class 'pydal.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'>, ...}
    itemname'mytest'
    locals{'A': <class 'gluon.html.A'>, 'ANY_OF': <class 'pydal.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'>, ...}
    level-1

Christian Varas

unread,
May 24, 2019, 12:36:53 AM5/24/19
to web...@googlegroups.com
I'm facing the same issue, did you already found the solution?

Btw, I'm running web2py in my android phone, maybe for me is quite different...

Cheers.
Chris.

--
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/2d6d9fdb-50a3-480a-a4b2-8642664003b5%40googlegroups.com.

Dave S

unread,
May 24, 2019, 2:12:20 AM5/24/19
to web2py-users


On Thursday, May 23, 2019 at 4:03:05 AM UTC-7, Константин Комков wrote:
Maybe it info can help?

Error snapshot help

<type 'exceptions.ImportError'>(No module named application.modules)

inspect attributes

Frames

    • File C:\inetpub\wwwroot\gluon\custom_import.py in custom_importer at line 74 код аргументы переменные

      Function argument list

      (name='mytest', globals={'A': <class 'gluon.html.A'>, 'ANY_OF': <class 'pydal.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 'pydal.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=None, level=-1)

    • [...]

    For what it's worth, I use a separate import line for each of my modules (but not for system modules), and I use the
    from mymod import myfunc1, myfunc2
    form of import line.
     
    /dps

    Константин Комков

    unread,
    May 24, 2019, 2:44:19 AM5/24/19
    to web2py-users
    Christian Varas, I don't find solution.
    Dave S, yes I tried import mytest like one line without system modules, and like that:
    from applications.application.modules import mytest
    Is "mymod" your app name?

    Константин Комков

    unread,
    May 24, 2019, 2:53:45 AM5/24/19
    to web2py-users
    from applications.application.modules import mytest
    >>>No module named application.modules
    from applications.application import mytest
    >>>No module named application
    from applications import mytest
    >>>cannot import name mytest
    My modul pass: C:\inetpub\wwwroot\applications\application\modules\mytest.py

    Dave S

    unread,
    May 24, 2019, 4:14:11 PM5/24/19
    to web2py-users

    No, "mymod" is my module name, in [web2pydir]/applications/myapp/modules/mymod.py  I am not using dotted notation.

    I would try changing your application name from "application" (if that isn't an editorial alias, like "myapp" is), because that may be name conflict within web2py.

    /dps

    Val K

    unread,
    May 26, 2019, 4:30:04 AM5/26/19
    to web2py-users
    There is 'site-packages' folder, modules that is placed in this folder can be imported in any application just as 'import foo' I think using this folder is better than importing across applications

    Константин Комков

    unread,
    May 27, 2019, 1:39:04 AM5/27/19
    to web...@googlegroups.com
    Dave S, it is as variant, but I think that if I change app name maybe somthing will broken. And links too.
    Val K, I have two controllers for enrants bachelor degree and magistracy. That controllers have many identical code and functions. I think it is not so good transfer part of app to another folder.

    Константин Комков

    unread,
    May 31, 2019, 8:10:23 AM5/31/19
    to web2py-users
    Dave S, today I rename my app from "application" to "statement". After that in browser I saw: 
    invalid function (default/statement). After that I restart server and "statement" start working. Then I tried to import my module, but have error again:
    import mytest
    >>>No module named statement.modules

    Dave S

    unread,
    May 31, 2019, 6:03:07 PM5/31/19
    to web2py-users


    Can you make a minimal app you can post here and that shows the same behavior?

    Also, from your traceback can you post the vars and args?

    /dps

    Message has been deleted
    Message has been deleted

    Константин Комков

    unread,
    Jun 6, 2019, 3:50:52 AM6/6/19
    to web2py-users

    Константин Комков

    unread,
    Jun 7, 2019, 4:55:49 AM6/7/19
    to web2py-users
    P.S. If you delete comment from default.py controller you can see that app don't work becouse dont have that module.
    Reply all
    Reply to author
    Forward
    0 new messages