Django导入错误'没有名为django的模块'

时间:2016-10-31 19:51:04

标签: django python-2.7 django-celery openshift-origin kombu

当我尝试在openshift上启动我的django应用程序时,我收到以下消息。因此部署失败......

File "wsgi/djangoProjectNew/manage.py", line 11, in <module>
    execute_from_command_line(sys.argv)
File "/var/lib/openshift/55555511111114444444444/python/virtenv/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
File "/var/lib/openshift/55555511111114444444444/python/virtenv/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/core/management/__init__.py", line 312, in execute
    django.setup()
File "/var/lib/openshift/55555511111114444444444/python/virtenv/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
File "/var/lib/openshift/55555511111114444444444/python/virtenv/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
File "/var/lib/openshift/55555511111114444444444/python/virtenv/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/apps/config.py", line 119, in create
    import_module(entry)
File "/opt/rh/python27/root/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named django

此应用是我几个月前设置的应用的副本。我改变了所有相关路径,名称等。 它在当地运行良好。

最后一个命令__init__.py在virtualenv之外运行是不是很奇怪?

我正在使用python2.7盒式磁带和github openshift示例https://github.com/openshift/django-example这个应用程序使用django 1.8.0作为依赖项。

这是从djangoProject.settings

安装的应用程序
INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'myDjangoApp',
    'djcelery',
    'kombu.transport.django',
    'progressbarupload',
    'widget_tweaks',
)

安装了Django:

[djangoProject-USERNAME.rhcloud.com data]\> which python
/var/lib/openshift/55555511111114444444444/python/virtenv/bin/python
[djangoProject-USERNAME.rhcloud.com data]\> python 
Python 2.7.8 (default, Aug  4 2016, 09:29:33) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.VERSION
(1, 8, 0, 'final', 0)
>>> 

进一步玩游戏后,我可以说它与一个或所有这些INSTALLED_APPS有关:

    'djcelery',
    'kombu.transport.django',
    'progressbarupload',

这是pip冻结:

amqp==2.1.1
Babel==0.9.6
billiard==3.5.0.1
celery==4.0.0rc6
Django==1.8
django-celery==3.1.17
django-smartfields==1.0.9
django-widget-tweaks==1.4.1
docutils==0.11
Extractor==0.6
Jinja2==2.6
kombu==4.0.0rc6
MarkupSafe==0.11
MySQL-python==1.2.3
nose==1.3.0
numpy==1.7.1
prelive==1.0
psycopg2==2.5.1
Pygments==1.5
pytz==2016.7
scipy==0.12.1
simplejson==3.2.0
six==1.7.3
Sphinx==1.1.3
SQLAlchemy==0.7.9
vine==1.1.3
virtualenv==13.1.0
Werkzeug==0.8.3
wheel==0.24.0

2 个答案:

答案 0 :(得分:1)

原因是&#39; kombu.transport.django&#39;在kombu 4.0.0中不再可用。

所以&#34; ImportError:没有名为django的模块&#34;正在抱怨软件包kombu中的模块,而不是软件包Django

使用kombu 3.0。**应该修复它。

答案 1 :(得分:0)

我将此添加到我的setup.py中,现在可以正常工作了。

install_requires=[
    'Django==1.8', 
    'django-celery==3.1.16', 
    'kombu==3.0.26', 
    'django-widget-tweaks==1.4.1', 
    'celery==3.1.18', 
    'django-crispy-forms==1.4.0', 
    ],