首页 > 解决方案 > ImportError:没有名为“django_select2”的模块

问题描述

我正在尝试将我的 django 应用程序部署在pythonanywhere. 我已经安装了应用程序所需的所有软件包。我还在django_select2我的应用程序中使用可重用的应用程序。

首先,我激活虚拟环境并django_select2通过以下命令安装:

$ pip install django_select2

当我执行以下命令时

$ pip freeze 
cryptography==2.2.2                                                                                                                                                                                               
Django==2.0.7                                                                                                                                                                                                     
django-appconf==1.0.2                                                                                                                                                                                             
django-select2==6.1.0                                                                                                                                                                                             
Flask==1.0.2                                                                                                                                                                                                      
Flask-JWT==0.3.2                                                                                                                                                                                                  
Flask-SQLAlchemy==2.3.2                                                                                                                                                                                           
furl==1.2                                                                                                                                                                                                         
idna==2.7   

如您所见django_select2,它也在安装列表中。我还检查site-packages了我的虚拟环境。还有django_select2文件夹。

但是,当我运行我的应用程序时,它会ImportError: No module named 'django_select2'在我的内部生成error.log

这是我的一部分error.log

2018-07-14 14:18:53,934: Error running WSGI application
2018-07-14 14:18:53,934: ImportError: No module named 'django_select2'
2018-07-14 14:18:53,934:   File "/var/www/harunergul_pythonanywhere_com_wsgi.py", line 22, in <module>
2018-07-14 14:18:53,935:     application = get_wsgi_application()
2018-07-14 14:18:53,935: 
2018-07-14 14:18:53,935:   File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application
2018-07-14 14:18:53,935:     django.setup(set_prefix=False)
2018-07-14 14:18:53,935: 
2018-07-14 14:18:53,935:   File "/usr/local/lib/python3.5/dist-packages/django/__init__.py", line 27, in setup
2018-07-14 14:18:53,935:     apps.populate(settings.INSTALLED_APPS)
2018-07-14 14:18:53,935: 
2018-07-14 14:18:53,935:   File "/usr/local/lib/python3.5/dist-packages/django/apps/registry.py", line 85, in populate
2018-07-14 14:18:53,936:     app_config = AppConfig.create(entry)
2018-07-14 14:18:53,936: 
2018-07-14 14:18:53,936:   File "/usr/local/lib/python3.5/dist-packages/django/apps/config.py", line 90, in create
2018-07-14 14:18:53,936:     module = import_module(entry)

有什么建议么?我错过了什么?

标签: djangopythonanywhere

解决方案


问题是在这种情况下应用程序没有使用虚拟环境。如果我们看下面的行,我们会看到/usr/local/...。所以应用程序使用pythonanywhere.com默认环境。

File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 13,

这意味着我们安装的任何东西virtualenv对默认服务器都没有影响。在pythonanywhere.comvirtualenv 菜单中,请确保在此菜单中输入正确的路径信息。


推荐阅读