Unable to import 'site' module and ImportError: No module named os

1,118 views
Skip to first unread message

Filipe Varjão

unread,
Jun 10, 2015, 6:58:29 PM6/10/15
to mod...@googlegroups.com
Hi all,

my wsgi.py file from a django project cannot import site module and not found os module. Isn't my first time, Isn't my first time, I think that the reason is python default version.

Apache_log
[notice] Apache/2.2.15 (Unix) DAV/2 PHP/5.3.3 mod_ssl/2.2.15 OpenSSL/1.0.1e-fips SVN/1.6.11 mod_wsgi/3.2 Python/2.6.6 configured -- resuming normal operations

I installed python2.7 and I put all into a virtualenv but I keep getting:

Apache_log
[error] mod_wsgi (pid=21347): Unable to import 'site' module.
[error] Traceback (most recent call last):
[error]   File "/var/www/html/portal/portal/portal.wsgi", line 1, in <module>
[error]     import os
[error] ImportError: No module named os

Many thanks.

Graham Dumpleton

unread,
Jun 10, 2015, 7:05:00 PM6/10/15
to mod...@googlegroups.com
The mod_wsgi module must be compiled for the specific Python version you intend using. Your mod_wsgi is compiled for Python 2.6. You cannot force it use a Python 2.7 installation by way of pointing it at the installation root or virtual environment for a Python 2.7 installation.

You would thus need to uninstall the system package mod_wsgi for Python 2.6 and install a Python 2.7 variant either from system packages if available, or compile it from source code yourself.

Given that your system packaged version of mod_wsgi is 3.2, which is hopelessly out of date and has a known security issue, you likely are going to have to compile from source code as at a guess your operating system version doesn't provide a newer version.

The latest mod_wsgi version is 4.4.12 and the recommended version to use. Older versions should not be used. It is also recommended you do not use Apache 2.2, especially with older mod_wsgi versions. Newest versions of mod_wsgi have various work arounds to get around memory usage issues in Apache 2.2 due to Apache 2.2's design in some areas. Those issues in Apache were fixed in Apache 2.4.

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 post to this group, send email to mod...@googlegroups.com.
Visit this group at http://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Filipe Varjão

unread,
Jun 11, 2015, 9:03:57 AM6/11/15
to mod...@googlegroups.com
Thank you Graham to reply, I got it reading this post ~> How to uninstall 'mod-wsgi' from httpd (Apache/2.2.15) - CentOS 6.6

and following this way.

# ldd /usr/lib64/httpd/modules/mod_wsgi.so  
    libpython2.6.so.1.0 => /usr/lib64/libpython2.6.so.1.0 (0x00002b3149c4e000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00002b3149f82000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00002b314a19d000)
    libutil.so.1 => /lib64/libutil.so.1 (0x00002b314a3a2000)
    libm.so.6 => /lib64/libm.so.6 (0x00002b314a5a5000)
    libc.so.6 => /lib64/libc.so.6 (0x00002b314a828000)
    /lib64/ld-linux-x86-64.so.2 (0x000000364b200000)

yum install httpd-devel


yum groupinstall "Development tools"
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel

cd ~
wget http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tgz
tar xvf Python-2.7.5.tgz
cd Python-2.7.5

./configure --enable-shared --with-threads
make
make install


cd ~
wget http://modwsgi.googlecode.com/files/mod_wsgi-3.4.tar.gz
tar xvf mod_wsgi-3.4.tar.gz
cd mod_wsgi-3.4

./configure  --with-python=/usr/local/bin/python2.7
make
make install


# ldd /usr/lib64/httpd/modules/mod_wsgi.so
    linux-vdso.so.1 =>  (0x00007fffde754000)
    libpython2.7.so.1.0 => /usr/local/lib/libpython2.7.so.1.0 (0x00007f9723498000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f972326d000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007f9723069000)
    libutil.so.1 => /lib64/libutil.so.1 (0x00007f9722e66000)
    libm.so.6 => /lib64/libm.so.6 (0x00007f9722be1000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f972284d000)
    /lib64/ld-linux-x86-64.so.2 (0x000000333e400000)


Thank you again.


Cheers,

Filipe

Filipe Varjão

unread,
Jun 11, 2015, 9:05:57 AM6/11/15
to mod...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages