使用Apache使用ImageKit部署Django时出错“无法导入名称conf”

时间:2015-12-26 00:17:56

标签: python django apache deployment django-imagekit

我正在尝试使用Apache部署我的Django站点,但我遇到了ImageKit库的问题。这是来自/var/log/apache2/error.log的错误:

group = models.ForeignKey(Group.objects.get_or_create(name="Free")[0])

有人知道可能导致这种情况发生的原因吗?做“sudo python3 manage.py runserver”工作正常,但是Apache遇到了这个库错误。以下是一些更相关的信息:

wsgi.py:

No handlers could be found for logger "django.request"
[1.2.3.4] mod_wsgi (pid=17276): Exception occurred processing WSGI script '/var/www/mysite.com/portfoliosite/portfoliosite/wsgi.py'.
[1.2.3.4] Traceback (most recent call last):
[1.2.3.4]   File "/home/ubuntu/.virtualenvs/portfoliositeenv/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 189, in __call__
[1.2.3.4]     response = self.get_response(request)
[1.2.3.4]   File "/home/ubuntu/.virtualenvs/portfoliositeenv/lib/python3.4/site-packages/django/core/handlers/base.py", line 218, in get_respo$
[1.2.3.4]     response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[1.2.3.4]   File "/home/ubuntu/.virtualenvs/portfoliositeenv/lib/python3.4/site-packages/django/core/handlers/base.py", line 264, in handle_un$
[1.2.3.4]     if resolver.urlconf_module is None:
[1.2.3.4]   File "/home/ubuntu/.virtualenvs/portfoliositeenv/lib/python3.4/site-packages/django/core/urlresolvers.py", line 395, in urlconf_mo$
[1.2.3.4]     self._urlconf_module = import_module(self.urlconf_name)
[1.2.3.4]   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
[1.2.3.4]     __import__(name)
[1.2.3.4]   File "/var/www/mysite.com/portfoliosite/portfoliosite/urls.py", line 21, in <module>
[1.2.3.4]     url(r'^', include('portfolio.urls')), # route root through portfolio routes
[1.2.3.4]   File "/home/ubuntu/.virtualenvs/portfoliositeenv/lib/python3.4/site-packages/django/conf/urls/__init__.py", line 33, in include
[1.2.3.4]     urlconf_module = import_module(urlconf_module)
[1.2.3.4]   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
[1.2.3.4]     __import__(name)
[1.2.3.4]   File "/var/www/mysite.com/portfoliosite/portfolio/urls.py", line 3, in <module>
[1.2.3.4]     from . import views
[1.2.3.4]   File "/var/www/mysite.com/portfoliosite/portfolio/views.py", line 9, in <module>
[1.2.3.4]     from .models import Project
[1.2.3.4]   File "/var/www/mysite.com/portfoliosite/portfolio/models.py", line 2, in <module>
[1.2.3.4]     from imagekit.models import ImageSpecField
[1.2.3.4]   File "/home/ubuntu/.virtualenvs/portfoliositeenv/lib/python3.4/site-packages/imagekit/__init__.py", line 2, in <module>
[1.2.3.4]     from . import conf
[1.2.3.4] ImportError: cannot import name conf

/etc/apache2/apache2.conf(我添加的部分):

import os
import sys
import site

# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('/home/ubuntu/.virtualenvs/portfoliositeenv/lib/python3.4/site-packages/')

# Add the app's directory to the PYTHONPATH
sys.path.append('/var/www/mysite.com/portfoliosite')
sys.path.append('/var/www/mysite.com/portfoliosite/portfoliosite')

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

# Activate your virtual env
activate_env=os.path.expanduser('/home/ubuntu/.virtualenvs/portfoliositeenv/bin/activate_this.py')
exec(open(activate_env).read(), dict(__file__=activate_env))

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

这真令人沮丧,任何帮助都会受到赞赏。谢谢!

1 个答案:

答案 0 :(得分:0)

想出来!我正在混合Python版本,你可以在日志中看到一些指向Python 2.7的路径,而我的virtualenv正在使用Python 3.我创建了一个新的虚拟环境并改变了使用Python 2.7的所有路径,它现在似乎正在工作。 / p>