2011-03-24 36 views
0

问题我升级的Python 2.5到2.6,但现在得到“导入错误:没有模块名为tagging.views”

的问题:它似乎像tagging模块,我有我的/srv/python-environments/saltycrane/lib/python2.5/site-packages/tagging没有被包括在内,因为我将系统升级到了2.6,尽管我假设在virtualenv模式下依赖2.5。

这里的错误/var/log/apache2/error.log

[Thu Mar 24 00:08:35 2011] [error] [client 127.0.0.1] mod_wsgi (pid=10470): Exception occurred processing WSGI script '/srv/workarounds/apache/django.wsgi'. 
[Thu Mar 24 00:08:35 2011] [error] [client 127.0.0.1] Traceback (most recent call last): 
[Thu Mar 24 00:08:35 2011] [error] [client 127.0.0.1] File "/usr/lib/pymodules/python2.6/django/core/handlers/wsgi.py", line 241, in __call__ 
[Thu Mar 24 00:08:35 2011] [error] [client 127.0.0.1]  response = self.get_response(request) 
[Thu Mar 24 00:08:35 2011] [error] [client 127.0.0.1] File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py", line 141, in get_response 
[Thu Mar 24 00:08:35 2011] [error] [client 127.0.0.1]  return self.handle_uncaught_exception(request, resolver, sys.exc_info()) 
[Thu Mar 24 00:08:35 2011] [error] [client 127.0.0.1] File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py", line 176, in handle_uncaught_exception 
[Thu Mar 24 00:08:35 2011] [error] [client 127.0.0.1]  if resolver.urlconf_module is None: 
[Thu Mar 24 00:08:35 2011] [error] [client 127.0.0.1] File "/usr/lib/pymodules/python2.6/django/core/urlresolvers.py", line 239, in _get_urlconf_module 
[Thu Mar 24 00:08:35 2011] [error] [client 127.0.0.1]  self._urlconf_module = import_module(self.urlconf_name) 
[Thu Mar 24 00:08:35 2011] [error] [client 127.0.0.1] File "/usr/lib/pymodules/python2.6/django/utils/importlib.py", line 35, in import_module 
[Thu Mar 24 00:08:35 2011] [error] [client 127.0.0.1]  __import__(name) 
[Thu Mar 24 00:08:35 2011] [error] [client 127.0.0.1] File "/srv/workarounds/urls.py", line 3, in <module> 
[Thu Mar 24 00:08:35 2011] [error] [client 127.0.0.1]  from tagging.views import tagged_object_list 
[Thu Mar 24 00:08:35 2011] [error] [client 127.0.0.1] ImportError: No module named tagging.views 

我的设置

首先,这里是我的设置:

$ python --version 
Python 2.6.6 
$ python 
>>> import django 
django.VERSION 
(1, 2, 3, 'final', 0) 

我的Django项目住在/srv。我的虚拟ENVS住在/srv/python-environments

如果我cd/srv/做:

source python-environments/saltycrane/bin/activate

Python的版本就变成了:

$ python --version 
Python 2.5.2 

我的项目,/srv/workarounds使用/srv/workarounds/apache/django.wsgi,它是由:

import os, sys, site 

virtualenv = '/srv/python-environments/saltycrane/' 

ALLDIRS = [os.path.join(virtualenv, 'lib', 'python%s' % sys.version[:3], 'site-packages')] 

# Remember original sys.path. 
prev_sys_path = list(sys.path) 

# Add project directory 
sys.path.append('/srv/') 
sys.path.append('/srv/workarounds/') 

for directory in ALLDIRS: 
    site.addsitedir(directory) 

new_sys_path = [] 
for item in list(sys.path): 
    if item not in prev_sys_path: 
     new_sys_path.append(item) 
     sys.path.remove(item) 

sys.path[:0] = new_sys_path 

os.environ['DJANGO_SETTINGS_MODULE'] = 'workarounds.settings' 

import django.core.handlers.wsgi 
application = django.core.handlers.wsgi.WSGIHandler() 

当Apache运行wsgi时,代码基本上将/srv//srv/workarounds添加到python路径中。

SO ....

如何调整我的wsgi使用Python 2.5.2,而不是2.6,以保持?或者,如果没有,我如何更新我的virtualenv使用Python 2.6包与pip

THINGS IM不知道

  1. 也许它运行在2.6和确实tagging模块,但标记模块或它的一部分是不兼容的,所以这就是为什么它抱怨No module named tagging.views

  2. 也许这与2.5到2.6无关,并始终存在?但是我非常怀疑这是因为我在代码中执行了几次重新启动,并且它工作正常。

  3. 它可能是一个Django微妙的版本更新,我可能已经更新1.1或1.2beta到1.2.3最后。

编辑:如果我有权利mod_wsgi.so,它编译为2.6。

/usr/lib/apache2/modules$ ldd mod_wsgi.so 
    linux-gate.so.1 => (0xf57fe000) 
    libpython2.6.so.1.0 => /usr/lib/libpython2.6.so.1.0 (0xb760f000) 
    libpthread.so.0 => /lib/libpthread.so.0 (0xb75f6000) 
    libdl.so.2 => /lib/libdl.so.2 (0xb75f2000) 
    libutil.so.1 => /lib/libutil.so.1 (0xb75ed000) 
    libm.so.6 => /lib/libm.so.6 (0xb75c7000) 
    libc.so.6 => /lib/libc.so.6 (0xb7482000) 
    libssl.so.0.9.8 => /usr/lib/i686/cmov/libssl.so.0.9.8 (0xb7438000) 
    libcrypto.so.0.9.8 => /usr/lib/i686/cmov/libcrypto.so.0.9.8 (0xb72e0000) 
    libz.so.1 => /usr/lib/libz.so.1 (0xb72cc000) 
    /lib/ld-linux.so.2 (0xb788e000) 
+0

能够前给出正确的建议,你需要验证编译的Python mod_wsgi的版本。参见'http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation#Python_Shared_Library'来解决这个问题。 – 2011-03-24 08:25:09

+0

@Graham Dumpleton - 我做了一个'sudo查找。从'/'命名'mod_wsgi.so'并将其提供给'ldd'。它似乎编译为2.6。 – 2011-03-24 14:23:58

回答

1

我认为,如果你改变了这一点,可能工作:

ALLDIRS = [os.path.join(virtualenv, 'lib', 'python%s' % sys.version[:3], 'site-packages')]

ALLDIRS = [os.path.join(virtualenv, 'lib', 'python2.5', 'site-packages')]

设置你的WSGIPythonHome就是使用的virtualenv与modwsgi时建议:

virtualenv --no-site-packages --python=python2.5 BASELINE 

和设置modwsgi使用,作为wsgipythonhome

Baseline Environment

The first step in using virtual environments with mod_wsgi is to point mod_wsgi at a baseline Python environment. This step is actually optional and if not done the main Python installation for the system, usually that which mod_wsgi was compiled for, would be used as the baseline environment.

Although the main Python installation can be used, especially in a shared environment where daemon mode of mod_wsgi is used to host WSGI applications for different users, it is better to make the baseline environment a virgin environment with an effectively empty 'site-packages' directory. This way there is no possibility of conflicts between modules and packages in a users individual Python virtual environment and the baseline environment.

To create a virgin environment using the 'virtualenv' program, the '--no-site-packages' option should be supplied when creating the environment.

$ cd /usr/local/pythonenv 

$ virtualenv --no-site-packages BASELINE 
New python executable in BASELINE/bin/python 
Installing setuptools............done. 

Note that the version of Python from which this baseline environment is created must be the same version of Python that mod_wsgi was compiled for. It is not possible to mix environments based on different major/minor versions of Python.

Once the baseline Python environment has been created, the WSGIPythonHome directive should be defined within the global part of the main Apache configuration files. The directive should refer to the top level directory for the baseline environment created by the 'virtualenv' script.

WSGIPythonHome /usr/local/pythonenv/BASELINE 

This Python environment will now be used as the baseline environment for all WSGI applications running under mod_wsgi, whether they be run in embedded mode or daemon mode.

There is no need to set the WSGIPythonHome directive if you want to use the main Python installation as the baseline environment.

+0

您不能使用WSGIPythonHome来使mod_wsgi使用与特定编译的mod_wsgi不同的主要/次要版本的Python。在使用不同的主要/次要版本的Python时,您也不应该从一个主要/次要版本的Python中将站点包目录添加到sys.path中。因此,我谨慎遵守这一建议。 OP需要确定构建的mod_wsgi的版本是否与所有版本相同,并且所有内容都使用相同的主版本/次版本。请参阅“http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation#Python_Shared_Library”。 – 2011-03-24 08:18:34

+0

这个建议是回答'我如何调整我的wsgi以继续使用Python 2.5.2而不是2.6?' – DTing 2011-03-24 08:20:44

+0

但是,如果他的mod_wsgi是针对Python 2.6编译的,那么您不能使用任何一种机制让它使用Python 2.5虚拟机环境。为不同版本的Python混合安装的东西是很危险的。如果他真的想继续使用Python 2.5并且mod_wsgi使用Python 2.6,唯一的解决方案是安装针对Python 2.5编译的mod_wsgi。在给出正确的建议之前,他们需要确定mod_wsgi正在使用哪个版本。 – 2011-03-24 08:23:44

相关问题