web2py returns an ImportError that can't find the module, but the .pyc file is in the _pycache__ dir

62 views
Skip to first unread message

João Matos

unread,
Mar 18, 2019, 4:42:53 PM3/18/19
to web2py-users
After installing a compiled app, web2py returns an ImportError that can't find the module, but the .pyc file is in the modules\__pycache__ dir.

The compiled app doesn't transport the module\general.py (which is correct) but it includes th __pycache__\*.pyc (which is also correct).
The problem seems to be that web2py doesn't search for the .pyc file inside the __pycache__ or that it doesn't recognize the naming used.

My module is called general.py and the .pyc file inside __pycache__ is called (automatically by Python) general.cpython-37.pyc.

Windows 7 Pro x64 SP1+all updates
web2py 2.18.4
Python 3.7.1 x86
Firefox 65.0.2 x64

Massimo Di Pierro

unread,
Mar 24, 2019, 2:35:19 PM3/24/19
to web2py-users
I recommend deleting __pycache__. It may be due switching between python 2 and python 3.

João Matos

unread,
Mar 24, 2019, 2:39:31 PM3/24/19
to web2py-users
I don't have or use Python 2, only Python 3.
You want me to delete the __pycache__ dir from my web2py (where I compile the app) or from the client end (where I install the compiled app)?

Massimo Di Pierro

unread,
Mar 24, 2019, 9:33:00 PM3/24/19
to web2py-users
Yes. Try delete it.

João Matos

unread,
Mar 25, 2019, 6:19:01 AM3/25/19
to web...@googlegroups.com
Which one? I asked with 2 options.

Massimo Di Pierro

unread,
Mar 25, 2019, 11:52:12 PM3/25/19
to web2py-users
all of them.

João Matos

unread,
Mar 26, 2019, 5:52:13 PM3/26/19
to web2py-users
I deleted both as instructed.
After that I compiled and installed the compiled app on the destination server.
The compiled app does not install the modules\general.py or the modules\general.pyc.

João Matos

unread,
Mar 26, 2019, 6:11:28 PM3/26/19
to web2py-users
If I recreate the modules\__pycache__ dir on my side, recompile and reinstall the app on the destination server, the compiled app copies the __pycache__ to the destination server when installing (which is correct), but does not copy the __pycache__\general.cpython-37.pyc to modules dir (which it think is the problem) and web2py returns the error
<class 'ImportError'> (ModuleNotFoundError("No module named 'applications.ajc.modules.general'"), <traceback object at 0x045733F0>)
when running the app.

If I on the destination server copy the modules\__pycache__\general.cpython-37.pyc to modules dir and change it's name to general.pyc, it all works.
It seems that web2py is not doing this last step.
Reply all
Reply to author
Forward
0 new messages