AttributeError:'module'对象没有属性'lru_cache'

问题描述 投票:3回答:3

我正在使用此环境设置获得标题中显示的错误。 Apache2与mod_wsgi,Python 3.5,Django 2.0.2。我正在使用virtualevn。

我的虚拟环境在:/ home / santosh / Documents / project / project /和django app在/ home / santosh / Documents / project / Reports

以下是wsgi.py文件的内容

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):目标WSGI脚本'/ home / santosh / Documents / project /Reports/Reports/wsgi.py'无法作为Python模块加载。

[Sun Feb 04 20:40:39.398284 2018] [wsgi:error] [pid 6428:tid 140043928524544] [client 127.0.0.1:60276] mod_wsgi(pid = 6428):处理WSGI脚本'/ 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(最近一次调用最后一次):

[Sun Feb 04 20:40:39.398475 2018] [wsgi:error] [pid 6428:tid 140043928524544] [client 127.0.0.1:60276]文件“/home/santosh/Documents/project/Reports/Reports/wsgi.py” ,第30行,在

[Sun Feb 04 20:40:39.398555 2018] [wsgi:error] [pid 6428:tid 140043928524544] [client 127.0.0.1:60276]来自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]文件“/home/santosh/Documents/project/project/lib/python3.5/ site-packages / django / init.py“,第1行,in

[Sun Feb 04 20:40:39.398591 2018] [wsgi:error] [pid 6428:tid 140043928524544] [client 127.0.0.1:60276]来自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]文件“/home/santosh/Documents/project/project/lib/python3.5/ site-packages / django / utils / version.py“,第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'对象没有属性'lru_cache'

django virtualenv python-3.5 mod-wsgi
3个回答
2
投票

经过大量的追踪,错误和谷歌搜索,最终我能够成功运行。

我得到了lru_cache错误,因为我做了sudo apt-get install libapache2-mod-wsgi来安装mod-wsgi。我认为这可能已安装到Ubuntu 16.04上的默认python,即python2.7。

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

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


1
投票

我跑了

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

在Ubuntu 18.04上安装Python3版本,然后重新加载Apache,这为我解决了错误。


0
投票

我偶然发现谷歌在寻找CentOS 7的结果,所以对于处于类似位置的人来说,这就是为我解决的问题:

当你yum install mod_wsgi,它安装python2版本。这会导致痛苦和痛苦以及像OP中的疯狂错误。

解决方案是在CentOS中安装来自IUS repo的python36(或者你正在使用的任何python3版本)版本。我不得不从pkgs.org下载,因为我的系统没有外部互联网访问权限,所以我不确定如何从yum开始,但我可以确认一旦我安装了兼容版本的mod_wsgi,一切都开始工作了。

© www.soinside.com 2019 - 2024. All rights reserved.