简体   繁体   English

ModuleNotFoundError:没有名为“django”的模块,具有虚拟环境 Python3.8

[英]ModuleNotFoundError: No module named 'django', with virtual environment Python3.8

Trying to run Django App along with Apache2 in Python3.8 Virtual environment.尝试在 Python3.8 虚拟环境中运行 Django 应用程序和 Apache2。 When I enter in to the python shell, I could import django.当我进入 python shell 时,我可以导入 django。 But when accessing webpage, it says "django not found"但是在访问网页时,它说“django not found”

As per the /var/log/apache2/error.log, following is the error根据/var/log/apache2/error.log,以下是错误

[Sun May 03 02:56:14.209910 2020] [wsgi:error] [pid 21516] [remote 192.168.1.5:58968] from django.core.wsgi import get_wsgi_application [Sun May 03 02:56:14.209966 2020] [wsgi:error] [pid 21516] [remote 192.168.1.5:58968] ModuleNotFoundError: No module named 'django' [Sun May 03 02:56:14.209910 2020] [wsgi:error] [pid 21516] [remote 192.168.1.5:58968] 从 django.core.wsgi import get_wsgi_application [Sun May 03 02:56:14.2092] [wsgi:2092]错误] [pid 21516] [远程192.168.1.5:58968] ModuleNotFoundError:没有名为“django”的模块

wsgi.py: wsgi.py:

import os,sys导入操作系统、系统

sys.path.append('/var/www/html/django-venv-py3.8/lib/python3.8/site-packages') sys.path.append('/var/www/html/django-venv-py3.8/lib/python3.8/site-packages')

from django.core.wsgi import get_wsgi_application从 django.core.wsgi 导入 get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'filebucket.settings') os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'filebucket.settings')

application = get_wsgi_application()应用程序 = get_wsgi_application()

default.conf默认.conf

(django-venv-py3.8) ramesh@Orktion:.../filebucket$ cat /etc/apache2/sites-available/000-default.conf (django-venv-py3.8) ramesh@Orktion:.../filebucket$ cat /etc/apache2/sites-available/000-default.conf

<Directory /var/www/html/django-venv-py3.8/filebucket/filebucket>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

WSGIDaemonProcess filebucket python-path=/var/www/html/django-venv-py3.8/filebucket python-home=/var/www/html/django-venv-py3.8
WSGIProcessGroup filebucket
WSGIScriptAlias / /var/www/html/django-venv-py3.8/filebucket/filebucket/wsgi.py

Alias /static /var/www/html/django-venv-py3.8/filebucket/static
<Directory /var/www/html/django-venv-py3.8/filebucket/static>
    Require all granted
</Directory>

Alias /media /var/www/html/django-venv-py3.8/filebucket/media
<Directory /var/www/html/django-venv-py3.8/filebucket/media>
    Require all granted
</Directory>

在此处输入图像描述

I have followed some troubleshooting articles, but no luck我关注了一些故障排除文章,但没有运气

try to install Django using the following command in windows CMD, and then try to execute it again: python -m django try to install Django using the following command in windows CMD, and then try to execute it again: python -m django

I hope this works:)我希望这有效:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM