AttributeError: 'module' 对象没有属性 'lru_cache' [英] AttributeError: 'module' object has no attribute 'lru_cache'

查看:100
本文介绍了AttributeError: 'module' 对象没有属性 'lru_cache'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此环境设置中标题所示的错误.Apache2 与 mod_wsgi ,Python 3.5,Django 2.0.2 .我正在使用 virtualevn.

Im getting the error as shown in title with this environment setup. Apache2 with mod_wsgi ,Python 3.5, Django 2.0.2 . I'm using virtualevn.

我的虚拟环境在:/home/santosh/Documents/project/project/和 django 应用程序在/home/santosh/Documents/project/Reports

my virtual env is in : /home/santosh/Documents/project/project/ and django app is in /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:tid140043928524544] [客户端 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.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:tid140043928524544] [客户端 127.0.0.1:60276] mod_wsgi (pid=6428):处理 WSGI 脚本时发生异常'/home/santosh/Documents/project/Reports/Reports/wsgi.py'.

[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:tid140043928524544] [客户端 127.0.0.1:60276] 回溯(最近一次调用最后):

[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:tid140043928524544] [客户端 127.0.0.1:60276] 文件/home/santosh/Documents/project/Reports/Reports/wsgi.py",第 30 行,在

[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:tid140043928524544] [客户端 127.0.0.1:60276] 来自 django.core.wsgi导入 get_wsgi_application

[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:tid140043928524544] [客户端 127.0.0.1:60276] 文件"/home/santosh/Documents/project/project/lib/python3.5/site-packages/django/init.py",第 1 行,在

[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:tid140043928524544] [客户端 127.0.0.1:60276] 来自django.utils.version 导入 get_version

[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:tid140043928524544] [客户端 127.0.0.1:60276] 文件"/home/santosh/Documents/project/project/lib/python3.5/site-packages/django/utils/version.py",第 61 行,在

[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:tid140043928524544] [客户端 127.0.0.1:60276] @functools.lru_cache()

[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:tid140043928524544] [客户端 127.0.0.1:60276] 属性错误:模块"对象没有属性 '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'

推荐答案

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

After lots of trail and error and googling, finally i was able to run successfully.

我收到了 lru_cache 错误,因为我执行了 sudo apt-get install libapache2-mod-wsgi安装 mod-wsgi.我认为这可能已安装到 Ubuntu 16.04(即 python2.7)上的默认 python.

I got the lru_cache error because, I did sudo apt-get install libapache2-mod-wsgi to install mod-wsgi. I think this might have installed to default python on Ubuntu 16.04 which is python2.7.

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

Solution: I uninstalled libapache2-mod-wsgi from ubuntu and installed it with pip install mod-wsgi and then finally copied the path of installed mod-wsgi from site-packages directory and updated it inside apache2/mods-available/wsgi.load file.

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

So its better to install mod-wsgi from virtualenv or normal python3 and then update apache files instead of installing libapache2-mod-wsgi directly on ubuntu.

这篇关于AttributeError: 'module' 对象没有属性 'lru_cache'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆