如何从virtualenv为Django执行Python

时间:2018-08-11 16:33:35

标签: django python-3.x centos7 wsgi django-wsgi

我已按照DigitalOcean的说明在具有Python 3.7.0的CentOS 7服务器上安装了Django 2.0.5 帖子。

添加conf文件后,出现以下错误

mod_wsgi (pid=21374): Target WSGI script '/home/user/myproject/myproject/wsgi.py' cannot be loaded as Python module.
mod_wsgi (pid=21374): Exception occurred processing WSGI script '/home/user/myproject/myproject/wsgi.py'.
Traceback (most recent call last):
  File "/home/user/myproject/myproject/wsgi.py", line 18, in <module>
    from django.core.wsgi import get_wsgi_application
  File "/home/user/myproject_env/lib/python3.7/site-packages/django/__init__.py", line 1, in <module>
    from django.utils.version import get_version
  File "/home/user/myproject_env/lib/python3.7/site-packages/django/utils/version.py", line 61, in <module>
    @functools.lru_cache()
AttributeError: 'module' object has no attribute 'lru_cache'

这表示由服务器的默认Python版本Python 2.7.5执行的 wsgi.py 文件。

为确认这一点,我从 wsgi.py error_log 添加了版本和$PYTHONPATH

ERROR:root:Python Version: 2.7.5
ERROR:root:['/home/user/myproject', '/home/user/myproject_env/bin/python3.7', 
'/home/user/myproject_env/lib/python3.7/site-packages', '/usr/lib64/python27.zip', 
'/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', 
'/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', 
'/usr/lib64/python2.7/site-packages', '/usr/lib/python2.7/site-packages']

它确认它正在执行Python 2.7.5而不是Python 3.7.0。

如何更改Django Python路径以从Python 3执行virtualenv

编辑:

这是我的 django.conf 文件:

Alias /static /home/user/myproject/static
<Directory /home/user/myproject/static>
    Require all granted
</Directory>

<Directory /home/user/myproject/myproject>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

WSGIDaemonProcess myproject python-path=/home/user/myproject:/home/user/myproject_env/lib/python3.7/site-packages
WSGIProcessGroup myproject
WSGIScriptAlias / /home/user/myproject/myproject/wsgi.py

0 个答案:

没有答案