ImportError: No module named site

23 views
Skip to first unread message

pcar...@gmail.com

unread,
Jan 25, 2021, 12:16:29 PM1/25/21
to modwsgi
Hello All,

I am setting up a new web server using the following:
(venv) [dev_user@96f98ccbad74 ~]$ pip freeze
asgiref==3.3.1
Django==3.1.5
mod-wsgi==4.7.1
pytz==2020.5
sqlparse==0.4.1

(venv) [dev_user@96f98ccbad74 ~]$ python --version
Python 3.6.8

(venv) [dev_user@96f98ccbad74 ~]$ httpd -v
Server version: Apache/2.4.6 (CentOS)

I used the following command to place the mod_wsgi module from 4.7.1 into the modules directory in the apache directory:
mod_wsgi-express install-module  

Which resulted in this output:
LoadModule wsgi_module "/home/dev_user/venv/lib64/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"
WSGIPythonHome "/home/dev_user/venv"

I removed the "" and placed those two lines in my httpd.conf file with some other lines as well:
LoadModule wsgi_module modules/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so

WSGIScriptAlias / /home/dev_user/integra/integra/wsgi.py
WSGIPythonHome /home/dev_user/venv
WSGIPythonPath /home/dev_user/integra

#IncludeOptional conf.d/*.conf

<Directory /home/dev_user/integra/integra>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

Directory structure
(venv) [dev_user@96f98ccbad74 home]$ ls dev_user
integra  venv
(venv) [dev_user@96f98ccbad74 home]$ ls dev_user/integra
core  integra  manage.py
(venv) [dev_user@96f98ccbad74 home]$ ls dev_user/integra/integra
asgi.py  __init__.py  settings.py  urls.py  wsgi.py

I'm not sure what I am missing but I cannot reach my site and the error in the log file is:
[Mon Jan 25 17:25:07.931962 2021] [:info] [pid 50384] mod_wsgi (pid=50384): Python home /home/dev_user/venv.
[Mon Jan 25 17:25:07.931997 2021] [:info] [pid 50384] mod_wsgi (pid=50384): Initializing Python.
ImportError: No module named site
ImportError: No module named site
ImportError: No module named site

Thank you for the help in advance!

Graham Dumpleton

unread,
Jan 25, 2021, 2:29:45 PM1/25/21
to mod...@googlegroups.com
If your Apache config file still has:

    LoadModule wsgi_module modules/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so

in it, then you likely still have the system package for mod_wsgi installed.

You can't use both at the same time and if it is for a different Python version than your virtual environment it can fail in the way shown.

You can also have it fail as you see when the Apache user cannot access inside your home directory because of filesystem permissions of SELinux.

It is better to not have the virtual environment and project code under your home directory, but under /var/www or other location that Apache does have access to.

Graham

--
You received this message because you are subscribed to the Google Groups "modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/modwsgi/63e157e4-be6b-4106-b5d0-5ea65baae75an%40googlegroups.com.

pcar...@gmail.com

unread,
Jan 25, 2021, 3:47:14 PM1/25/21
to modwsgi
As usual you are right Graham removed the old mod_wsgi from the httpd directories and moved my project to var/www.  My welcome page is up.  Thank you!
Reply all
Reply to author
Forward
0 new messages