关于django:AttributeError:’module’对象没有属性’lru_cache’

AttributeError: 'module' object has no attribute 'lru_cache'

我得到错误,如标题所示,与此环境设置。带mod wsgi的Apache2,python 3.5,django 2.0.2。我正在使用virtualevn。

我的虚拟环境位于:/home/santosh/documents/project/project/django应用程序在/home/santosh/documents/project/reports中

下面是wsgi.py文件的内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import os, sys


sys.path.append('/home/santosh/Documents/project/Reports/Reports')
sys.path.append('/home/santosh/Documents/project/Reports')


sys.path.append('/home/santosh/Documents/project/project/lib/python3.5/site-packages')
sys.path.append('/home/santosh/Documents/project/project/lib/python3.5')
sys.path.append('/home/santosh/Documents/project/project/bin')



from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE","Reports.settings")

application = get_wsgi_application()

堆栈跟踪:

[Sun Feb 04 20:40:39.396427 2018] [wsgi:error] [pid 6428:tid
140043928524544] [client 127.0.0.1:60276] mod_wsgi (pid=6428): Target
WSGI script '/home/santosh/Documents/project/Reports/Reports/wsgi.py'
cannot be loaded as Python module.

[Sun Feb 04 20:40:39.398284 2018] [wsgi:error] [pid 6428:tid
140043928524544] [client 127.0.0.1:60276] mod_wsgi (pid=6428):
Exception occurred processing WSGI script
'/home/santosh/Documents/project/Reports/Reports/wsgi.py'.

[Sun Feb 04 20:40:39.398425 2018] [wsgi:error] [pid 6428:tid
140043928524544] [client 127.0.0.1:60276] Traceback (most recent call
last):

[Sun Feb 04 20:40:39.398475 2018] [wsgi:error] [pid 6428:tid
140043928524544] [client 127.0.0.1:60276] File
"/home/santosh/Documents/project/Reports/Reports/wsgi.py", line 30, in

[Sun Feb 04 20:40:39.398555 2018] [wsgi:error] [pid 6428:tid
140043928524544] [client 127.0.0.1:60276] from django.core.wsgi
import get_wsgi_application

[Sun Feb 04 20:40:39.398565 2018] [wsgi:error] [pid 6428:tid
140043928524544] [client 127.0.0.1:60276] File
"/home/santosh/Documents/project/project/lib/python3.5/site-packages/django/init.py",
line 1, in

[Sun Feb 04 20:40:39.398591 2018] [wsgi:error] [pid 6428:tid
140043928524544] [client 127.0.0.1:60276] from
django.utils.version import get_version

[Sun Feb 04 20:40:39.398598 2018] [wsgi:error] [pid 6428:tid
140043928524544] [client 127.0.0.1:60276] File
"/home/santosh/Documents/project/project/lib/python3.5/site-packages/django/utils/version.py",
line 61, in

[Sun Feb 04 20:40:39.398628 2018] [wsgi:error] [pid 6428:tid
140043928524544] [client 127.0.0.1:60276] @functools.lru_cache()

[Sun Feb 04 20:40:39.398643 2018] [wsgi:error] [pid 6428:tid
140043928524544] [client 127.0.0.1:60276] AttributeError: 'module'
object has no attribute 'lru_cache'


经过大量的跟踪、错误和谷歌搜索,我终于能够成功地运行了。

我得到了lru缓存错误,因为我安装了libapache2 mod wsgi安装mod wsgi。我认为这可能已经在Ubuntu16.04上安装了默认的python2.7。

解决方案:我从Ubuntu卸载了libapache2 mod wsgi,并用pip install mod-wsgi安装了它,最后从site packages目录复制了安装的mod wsgi的路径,并在apache2/mods available/wsgi.load文件中进行了更新。

所以最好从virtualenv或normal python3安装mod wsgi,然后更新apache文件,而不是直接在Ubuntu上安装libapache2 mod wsgi。


我跑

1
2
sudo apt remove  libapache2-mod-wsgi
sudo apt install libapache2-mod-wsgi-py3

在Ubuntu18.04上安装python3版本,然后重新加载apache,这为我解决了错误。


我在谷歌(Google)上无意中找到了Centos 7的搜索结果,所以对于任何一个处境相似的人,以下是我的解决方案:

当您使用cx1〔1〕时,它会安装python2版本。这会导致痛苦和痛苦,以及像手术中那样的疯狂错误。

解决方案是从CentOS的IUS repo安装python36(或您使用的任何python3版本)版本。我必须从pkgs.org下载,因为我的系统没有外部互联网接入,所以我不确定如何从yum下载,但我可以确认,一旦我安装了兼容版本的mod_wsgi,一切都开始工作。