无法使用系统版本的python 2.7.6而不是virtualenv版本停止apache

时间:2016-04-27 03:14:47

标签: linux apache python-2.7 ubuntu mod-wsgi

我使用:

重新编译了python2.7.11
./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

我已经安装了django和所有依赖项,检查pip位于我的新python版本中

我卸载了mod_wsgi和的打包版本 我已经通过以下方式将mod_wsgi链接到新版本的python:

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

当我重新启动apache时,似乎启动了2.7.6和2.7.11:

[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

我的httpd.conf看起来像:

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>

我能够运行“hello world”wsgi应用程序,即使似乎使用了两个版本的python。但是,当我使用django应用程序时,我最终得到的ImportError似乎与多个版本有关。

[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

回复@Graham:make命令失败,如下:

/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

1 个答案:

答案 0 :(得分:0)

尝试:

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

构建时LD_RUN_PATH环境变量将包含正确库的目录路径嵌入到mod_wsgi.so文件的查找路径中。