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

心已入冬 提交于 2020-06-16 03:13:33

问题


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.

my virtual env is in : /home/santosh/Documents/project/project/ and django app is in /home/santosh/Documents/project/Reports

Below is the content of wsgi.py file

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()

Stacktrace:

[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'


回答1:


I stumbled here from Google looking for a result for CentOS 7, so for anyone in a similar position, here's what fixed it for me:

When you yum install mod_wsgi, it installs the python2 version. This causes pain and suffering and crazy errors like in OP.

The solution is to install the python36 (or whatever python3 version you're using) version from the IUS repo in CentOS. I had to download from pkgs.org because my system doesn't have external internet access, so I'm not sure how to do it from yum, but I can confirm that once I installed a compatible version of mod_wsgi everything started working.




回答2:


I ran

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

to install the Python3 version on Ubuntu 18.04 and afterwards reloaded Apache, which solved the error for me.




回答3:


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

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.

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.

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.



来源:https://stackoverflow.com/questions/48609614/attributeerror-module-object-has-no-attribute-lru-cache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!