我已经在'pythonanywhere'上实现了Django应用程序,但是当我尝试在日志中加载网站时,会看到以下信息:
2019-02-27 20:20:37,677: Error running WSGI application
2019-02-27 20:20:37,678: ImportError: No module named 'crispy_forms'
2019-02-27 20:20:37,679: File "/var/www/zen404_pythonanywhere_com_wsgi.py", line 15, in <module>
2019-02-27 20:20:37,679: application = get_wsgi_application()
2019-02-27 20:20:37,679:
2019-02-27 20:20:37,679: File "/home/zen404/.virtualenvs/zen404.pythonanywhere.com/lib/python3.5/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2019-02-27 20:20:37,679: django.setup(set_prefix=False)
2019-02-27 20:20:37,684:
2019-02-27 20:20:37,684: File "/home/zen404/.virtualenvs/zen404.pythonanywhere.com/lib/python3.5/site-packages/django/__init__.py", line 24, in setup
2019-02-27 20:20:37,684: apps.populate(settings.INSTALLED_APPS)
2019-02-27 20:20:37,684:
2019-02-27 20:20:37,684: File "/home/zen404/.virtualenvs/zen404.pythonanywhere.com/lib/python3.5/site-packages/django/apps/registry.py", line 89, in populate
2019-02-27 20:20:37,685: app_config = AppConfig.create(entry)
2019-02-27 20:20:37,685:
2019-02-27 20:20:37,685: File "/home/zen404/.virtualenvs/zen404.pythonanywhere.com/lib/python3.5/site-packages/django/apps/config.py", line 90, in create
2019-02-27 20:20:37,685: module = import_module(entry)
当然,我在其中安装了虚拟环境和“ crispy_forms”。什么会触发此错误?当我在Bash PythonAnywhere中运行python3 manage.py runserver命令时,服务器正确启动。但是在日志中,错误仍然可见,并且基本页面无法正常工作。
任何帮助将不胜感激。
编辑
2019-02-27 21:55:48,333: Error running WSGI application
2019-02-27 21:55:48,334: ImportError: No module named 'crispy_forms'
2019-02-27 21:55:48,334: File "/var/www/zen404_pythonanywhere_com_wsgi.py", line 15, in <module>
2019-02-27 21:55:48,334: application = get_wsgi_application()
2019-02-27 21:55:48,335:
2019-02-27 21:55:48,335: File "/home/zen404/.virtualenvs/zen404.pythonanywhere.com/lib/python3.5/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2019-02-27 21:55:48,335: django.setup(set_prefix=False)
2019-02-27 21:55:48,335:
2019-02-27 21:55:48,335: File "/home/zen404/.virtualenvs/zen404.pythonanywhere.com/lib/python3.5/site-packages/django/__init__.py", line 24, in setup
2019-02-27 21:55:48,335: apps.populate(settings.INSTALLED_APPS)
2019-02-27 21:55:48,335:
2019-02-27 21:55:48,336: File "/home/zen404/.virtualenvs/zen404.pythonanywhere.com/lib/python3.5/site-packages/django/apps/registry.py", line 89, in populate
2019-02-27 21:55:48,336: app_config = AppConfig.create(entry)
2019-02-27 21:55:48,336:
2019-02-27 21:55:48,336: File "/home/zen404/.virtualenvs/zen404.pythonanywhere.com/lib/python3.5/site-packages/django/apps/config.py", line 90, in create
2019-02-27 21:55:48,336: module = import_module(entry)
2019-02-27 21:55:48,336: ***************************************************
2019-02-27 21:55:48,336: If you're seeing an import error and don't know why,
2019-02-27 21:55:48,336: we have a dedicated help page to help you debug:
2019-02-27 21:55:48,337: https://help.pythonanywhere.com/pages/DebuggingImportError/
2019-02-27 21:55:48,337: ***************************************************
BASH
(zen404.pythonanywhere.com) 21:54 ~ $ which python
/home/zen404/.virtualenvs/zen404.pythonanywhere.com/bin/python
(zen404.pythonanywhere.com) 21:55 ~ $ python -V
Python 3.5.2
(zen404.pythonanywhere.com) 21:55 ~ $ pip3 install --upgrade django-crispy-forms
Looking in links: /usr/share/pip-wheels
Requirement already up-to-date: django-crispy-forms in ./.virtualenvs/zen404.pythonanywhere.com/lib/python3.5/site-packages (1.7.2)
(zen404.pythonanywhere.com) 21:55 ~ $
答案 0 :(得分:2)
确定要在正确的环境中安装软件包吗?
在通过bash为虚拟环境安装软件包之前,必须先激活它:
# activate the virtualenv, adapt the path if necessary:
source /home/zen404/.virtualenvs/zen404.pythonanywhere.com/bin/activate
# checkout if the python executable is from your virtualenv
which python
# THEN install your package - for the activated virtual env
pip install --upgrade django-crispy-forms