Skip to content
Advertisement

Unable to stop apache using system version of python 2.7.6 instead of virtualenv version

I have recompiled python2.7.11 using:

./configure
make
make altinstall
sudo ln -s /usr/local/bin/python2.7 /usr/local/bin/python
wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo /usr/local/bin/python
sudo /usr/local/bin/easy_install pip
sudo pip install virtualenv
sudo pip install virtualenvwrapper
source /usr/local/bin/virtualenvwrapper.sh

I have installed django and all the dependencies checking that the pip is located in my new python version

I uninstalled the packaged version of mod_wsgi and I have linked mod_wsgi to the new version of python by:

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

When I restart apache both 2.7.6 and 2.7.11 seem to be started:

[Wed Apr 27 01:46:21.085703 2016] [wsgi:warn] [pid 18410:tid 140116611360640] mod_wsgi: Compiled for Python/2.7.11.
[Wed Apr 27 01:46:21.085775 2016] [wsgi:warn] [pid 18410:tid 140116611360640] mod_wsgi: Runtime using Python/2.7.6.
[Wed Apr 27 01:46:21.086641 2016] [mpm_worker:notice] [pid 18410:tid 140116611360640] AH00292: Apache/2.4.7 (Ubuntu) OpenSSL/1.0.1f mod_wsgi/4.5.2 Python/2.7.6 configured -- resuming normal operations

My httpd.conf looks like:

WSGIPythonHome /home/vagrant/.virtualenvs/django_2.7.11_env
<VirtualHost *:80>
  ServerName server.dev
  ServerAlias www.server.dev

  WSGIDaemonProcess server.dev python-path=/var/www/app:/home/vagrant/.virtualenvs/django_2.7.11_env/lib/python2.7/site-packages
  WSGIProcessGroup server.dev

  ## Vhost docroot
  DocumentRoot "/var/www/app"
  Alias "/sitemap.xml" "/var/www/app/static/sitemap.xml"
  <Directory /var/www/app/static>
      Require all granted
  </Directory>


    <Directory /var/www/wsgi-scripts>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>

  ## Logging
  ErrorLog "/var/log/apache2/av_app_nma_api_error.log"
  ServerSignature Off
  CustomLog "/var/log/apache2/av_app_nma_api_access.log" combined

  WSGIScriptAlias / /var/www/wsgi-scripts/wsgi.py
</VirtualHost>

I am able to run the “hello world” wsgi application even though both versions of python seem to be used. However, when I use the django app I end up with an ImportError that seems to be related to the multiple versions.

[Wed Apr 27 02:34:42.956988 2016] [wsgi:info] [pid 20244:tid 140656494913280] mod_wsgi (pid=20244): Adding '/home/vagrant/.virtualenvs/django_2.7.11_env/lib/python2.7/site-packages' to path.
[Wed Apr 27 02:34:42.957356 2016] [wsgi:info] [pid 20244:tid 140656494913280] [remote 192.168.56.1:1070] mod_wsgi (pid=20244, process='server.dev', application='server.dev|'): Loading WSGI script '/var/www/wsgi-scripts/wsgi.py'.
[Wed Apr 27 02:34:42.995218 2016] [wsgi:error] [pid 20244:tid 140656494913280] [remote 192.168.56.1:1070] mod_wsgi (pid=20244): Target WSGI script '/var/www/wsgi-scripts/wsgi.py' cannot be loaded as Python module.
[Wed Apr 27 02:34:42.995328 2016] [wsgi:error] [pid 20244:tid 140656494913280] [remote 192.168.56.1:1070] mod_wsgi (pid=20244): Exception occurred processing WSGI script '/var/www/wsgi-scripts/wsgi.py'.
[Wed Apr 27 02:34:42.995376 2016] [wsgi:error] [pid 20244:tid 140656494913280] [remote 192.168.56.1:1070] Traceback (most recent call last):
[Wed Apr 27 02:34:42.995419 2016] [wsgi:error] [pid 20244:tid 140656494913280] [remote 192.168.56.1:1070]   File "/var/www/wsgi-scripts/wsgi.py", line 18, in <module>
[Wed Apr 27 02:34:42.995945 2016] [wsgi:error] [pid 20244:tid 140656494913280] [remote 192.168.56.1:1070]     from django.core.wsgi import get_wsgi_application
[Wed Apr 27 02:34:42.995998 2016] [wsgi:error] [pid 20244:tid 140656494913280] [remote 192.168.56.1:1070]   File "/home/vagrant/.virtualenvs/django_2.7.11_env/lib/python2.7/site-packages/django/core/wsgi.py", line 2, in <module>
[Wed Apr 27 02:34:42.996068 2016] [wsgi:error] [pid 20244:tid 140656494913280] [remote 192.168.56.1:1070]     from django.core.handlers.wsgi import WSGIHandler
[Wed Apr 27 02:34:42.996109 2016] [wsgi:error] [pid 20244:tid 140656494913280] [remote 192.168.56.1:1070]   File "/home/vagrant/.virtualenvs/django_2.7.11_env/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 10, in <module>
[Wed Apr 27 02:34:42.996209 2016] [wsgi:error] [pid 20244:tid 140656494913280] [remote 192.168.56.1:1070]     from django import http
[Wed Apr 27 02:34:42.996249 2016] [wsgi:error] [pid 20244:tid 140656494913280] [remote 192.168.56.1:1070]   File "/home/vagrant/.virtualenvs/django_2.7.11_env/lib/python2.7/site-packages/django/http/__init__.py", line 2, in <module>
[Wed Apr 27 02:34:42.996316 2016] [wsgi:error] [pid 20244:tid 140656494913280] [remote 192.168.56.1:1070]     from django.http.request import (
[Wed Apr 27 02:34:42.996355 2016] [wsgi:error] [pid 20244:tid 140656494913280] [remote 192.168.56.1:1070]   File "/home/vagrant/.virtualenvs/django_2.7.11_env/lib/python2.7/site-packages/django/http/request.py", line 10, in <module>
[Wed Apr 27 02:34:42.996499 2016] [wsgi:error] [pid 20244:tid 140656494913280] [remote 192.168.56.1:1070]     from django.core import signing
[Wed Apr 27 02:34:42.996560 2016] [wsgi:error] [pid 20244:tid 140656494913280] [remote 192.168.56.1:1070]   File "/home/vagrant/.virtualenvs/django_2.7.11_env/lib/python2.7/site-packages/django/core/signing.py", line 48, in <module>
[Wed Apr 27 02:34:42.996663 2016] [wsgi:error] [pid 20244:tid 140656494913280] [remote 192.168.56.1:1070]     from django.utils.crypto import constant_time_compare, salted_hmac
[Wed Apr 27 02:34:42.996705 2016] [wsgi:error] [pid 20244:tid 140656494913280] [remote 192.168.56.1:1070]   File "/home/vagrant/.virtualenvs/django_2.7.11_env/lib/python2.7/site-packages/django/utils/crypto.py", line 8, in <module>
[Wed Apr 27 02:34:42.996792 2016] [wsgi:error] [pid 20244:tid 140656494913280] [remote 192.168.56.1:1070]     import hmac
[Wed Apr 27 02:34:42.996830 2016] [wsgi:error] [pid 20244:tid 140656494913280] [remote 192.168.56.1:1070]   File "/usr/local/lib/python2.7/hmac.py", line 8, in <module>
[Wed Apr 27 02:34:42.997049 2016] [wsgi:error] [pid 20244:tid 140656494913280] [remote 192.168.56.1:1070]     from operator import _compare_digest as compare_digest
[Wed Apr 27 02:34:42.997102 2016] [wsgi:error] [pid 20244:tid 140656494913280] [remote 192.168.56.1:1070] ImportError: cannot import name _compare_digest

Reply to @Graham: The make command fails with following:

/usr/bin/ld: /usr/local/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32S against `_Py_NotImplementedStruct' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libpython2.7.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
apxs:Error: Command failed with rc=65536
.
make: *** [src/server/mod_wsgi.la] Error 1

Advertisement

Answer

Try:

make distclean
./configure --with-python=/usr/local/bin/python
LD_RUN_PATH=/usr/local/lib make
sudo make install

The LD_RUN_PATH environment variable when building embeds the directory path containing the correct library into the lookup path for the mod_wsgi.so file.

Advertisement