No module named django.core.wsgi, Apache+ CentOS

808 views
Skip to first unread message

ANi

unread,
Jan 15, 2019, 11:04:23 PM1/15/19
to Django users
Hey guys.
I am trying to deploy my Django project on CentOS 7 with Apache.
and I got an error of  ImportError: No module named django.core.wsgi
I think it is because the Apache did not use the python version inside the virtualenv
However I dont know where the problem is.

this is my httpd.conf 
WSGIProcessGroup project
WSGIDaemonProcess project python-path=/var/www/html/project:/var/www/html/inv/Lib/python3.7/site-packages
WSGIPythonPath /var/www/html/project:/var/www/html/inv/Lib/python3.7/site-packages

Alias /static "/var/www/html/project/static-files"
<Directory "/var/www/html/project/static-files">
       
Require all granted
</Directory>


<Directory "/
var/www/html/project/project">
<Files wsgi.py>
        Require all granted
</Files>

I install wsgi_mod by yum install mod_wsgi
[mpm_prefork:notice] [pid 25884] AH00163: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips mod_fcgid/2.3.9 mod_wsgi/3.4 Python/2.7.5 configured -- resuming normal operations



Thank you in advance.

Michal Petrucha

unread,
Jan 16, 2019, 4:50:10 AM1/16/19
to Django users
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

On Tue, Jan 15, 2019 at 08:04:23PM -0800, ANi wrote:
> Hey guys.

Maybe consider asking not just the guys next time. ;)

> I am trying to deploy my Django project on CentOS 7 with Apache.
> and I got an error of *ImportError: No module named django.core.wsgi*
> I think it is because the Apache did not use the python version inside the
> virtualenv
> However I dont know where the problem is.
>
> this is my httpd.conf
> WSGIProcessGroup project
> WSGIDaemonProcess project python-path=/var/www/html/project:/var/www/html/
> inv/Lib/python3.7/site-packages
> WSGIPythonPath /var/www/html/project:/var/www/html/inv/Lib/python3.7/site-
> packages
>
> Alias /static "/var/www/html/project/static-files"
> <Directory "/var/www/html/project/static-files">
> Require all granted
> </Directory>
>
>
> <Directory "/var/www/html/project/project">
> <Files wsgi.py>
> Require all granted
> </Files>
>
> I install wsgi_mod by *yum install mod_wsgi*
> [mpm_prefork:notice] [pid 25884] AH00163: Apache/2.4.6 (CentOS) OpenSSL/1.0.
> 2k-fips mod_fcgid/2.3.9 mod_wsgi/3.4 Python/2.7.5 configured -- resuming
> normal operations

As the log line above indicates, the mod_wsgi you're using is built
against Python 2.7.5, but you're configuring it to point to a Python
3.7 environment; that will not work.

A quick search of the internets indicates that CentOS 7 does not
provide a mod_wsgi package built against any other version of Python
than 2.7, which means you'll need to build it yourself.

One way would be to use pip to install mod_wsgi in your application's
virtualenv (you'll need to ensure that you have all the necessary
header files for apache and Python installed), and then execute::

mod_wsgi-express module-config

which will show you the lines you need to insert into your apache
config in order to use that build of mod_wsgi. More details are
explained at
https://pypi.org/project/mod_wsgi/#connecting-into-apache-installation.

Good luck,

Michal
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBCgAGBQJcPv4XAAoJEHA7T/IPM/klJ9MQAMYJ60aXMk2c1ZsqIP0yuRfS
GEOKVGM53pPTKWBt74fVkMSRCg8A6pC/Vmwka9f/wBCbG6/5QeFzYu0usuiTTGM0
m3KjjddEr0f7zr4KABkzsT9Q7F1gRymRqG3tqec40dLTPfLbiyITy5MUBGi0g8VS
cqSHfXhqQLHls3EjqH5gDgQy9i7J3GvJmjO5be9HEqnukO3o2NIff6mCnTmx1+TX
irvnXJ3th29j8Z7iHHl11JzWQgNQf4xKPZkpIb8x9DcZ66Its7fnx//bAkWcngAw
BpglB3GkAuyLi8XgTDlSEkwbNqJS00bjwZ/RWzfHwnXyu684quZMqDdLk7pJdn0I
uJH0d47zb3NHlOy1ODBrkds6QJMxW84x5jMpZnmeCs0O+h4A+zm42TFvTGKf7DlG
Tu8p5ZjMLD1oB1MEypdXJuURO2fUKigHHMjstBl7oJ04zoaZ8UWgJnMAxrjRCIJH
G0u4Un/O5cMTAKEzakaHvn0FJ5okwXhF+Pdn8g5oIPedBZNhiG4jg7cu4VjOz3/s
B/FADAh/ZHPkLe9aMe/I4L+oMxr4daCDw09TiT4eMFH8qYkIv+VBqRx9Gb7d0Fu5
Gp74k7cclszfSSfXZzIM+AAsDhTg+njzOgMO6tazYW/APBABOWQygvgtEGPvgOJo
Ln0azAuyh+PShZW5JXeg
=X2I7
-----END PGP SIGNATURE-----

ANi

unread,
Jan 16, 2019, 8:46:47 PM1/16/19
to Django users
Thank you and after facing so much mysterious(at least to me) errors,
I failed to install it through pip(I have no idea why)
so I tried to get it from compiling the source code, and it failed as well.
I started over and install python through the repository rather than source code,
and I compile the mod_wsgi myself using the python I've installed, get it done in a few minutes.lol
 
Now I am dealing with another mysterious problem. ˊ___>ˋ
seems endless...

ANi於 2019年1月16日星期三 UTC+8下午12時04分23秒寫道:
Reply all
Reply to author
Forward
0 new messages