Solution for ImportError: No module named web

Once I needed to disable the Nginx web server on the same server with iRedmail and install Apache2. And when I tried to start iRedadmin, it did not open, and in the Apache2 logs I saw:

mod_wsgi (pid=233705): Failed to exec Python script file '/opt/www/iredadmin/iredadmin.py'.
mod_wsgi (pid=233705): Exception occurred processing WSGI script '/opt/www/iredadmin/iredadmin.py'.
Traceback (most recent call last):
File "/opt/www/iredadmin/iredadmin.py", line 8, in <module>
from libs import iredbase
File "/opt/www/iredadmin/libs/iredbase.py", line 5, in <module>
import web
ImportError: No module named web

I tried installing the web.py web framework for Python:

pip3 install web.py
pip3 install web.py==0.62

But it turned out that it was already installed:

Requirement already satisfied: web.py in /usr/local/lib/python3.8/dist-packages (0.62)
Requirement already satisfied: cheroot in /usr/local/lib/python3.8/dist-packages (from web.py) (8.5.2)
Requirement already satisfied: jaraco.functools in /usr/local/lib/python3.8/dist-packages (from cheroot->web.py) (3.1.0)
Requirement already satisfied: six>=1.11.0 in /usr/lib/python3/dist-packages (from cheroot->web.py) (1.14.0)
Requirement already satisfied: more-itertools>=2.6 in /usr/local/lib/python3.8/dist-packages (from cheroot->web.py) (8.6.0)

I ended up solving the problem by installing libapache2-mod-wsgi-py3:

sudo apt install libapache2-mod-wsgi-py3

After that, the error disappeared.
And you need to run not “python”, but “python3”.

python3 wblist_admin.py --list --whitelist
python3 wblist_admin.py --list --blacklist

Example configuration for iredadmin just in case:

WSGISocketPrefix /var/run/wsgi
WSGIDaemonProcess iredadmin user=iredadmin threads=15
WSGIProcessGroup iredadmin

AddType text/html .py

<Directory /opt/www/iredadmin/>
    <IfVersion < 2.4>
        Order deny,allow
        Allow from all
    </IfVersion>
    <IfVersion >= 2.4>
        Require all granted
    </IfVersion>
</Directory>

Alias /iredadmin/static "/opt/www/iredadmin/static/"
WSGIScriptAlias /iredadmin "/opt/www/iredadmin/iredadmin.py/"

See also my articles:
Installing and Configuring the Apache2 Web Server
Installing and configuring iRedMail
Install and configure Nginx

Leave a comment

Leave a Reply