导入错误:没有名为django的模块 - 用于特定项目

时间:2016-11-24 17:09:19

标签: django python-2.7 ubuntu python-import

我已经在我的Ubuntu 16.04中安装了Django(1.8.2) 当我将一个工作项目克隆到它并运行服务器时,我收到以下错误。

Traceback (most recent call last):
    File "manage.py", line 31, in <module>
      execute_from_command_line(sys.argv)
  File "/usr/lib/python2.7/django/core/management/__init__.py", line 338,  in execute_from_command_line
    utility.execute()
  File "/usr/lib/python2.7/django/core/management/__init__.py", line 312, in execute
    django.setup()
  File "/usr/lib/python2.7/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/lib/python2.7/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/usr/lib/python2.7/django/apps/config.py", line 119, in create
    import_module(entry)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
  __import__(name)
ImportError: No module named django

观察:

  • 我可以启动一个新项目并运行相同的服务器。
  • INSTALLED_APPSsettings.py的值为:

    INSTALLED_APPS = (
       'django.contrib.admin',
       'django.contrib.auth',
       'django.contrib.contenttypes',
       'django.contrib.sessions',
       'django.contrib.messages',
       'django.contrib.staticfiles',
       'Telecommands',
       'Telemetry',
       'captcha',
       'django.contrib.sitemaps',
       'djcelery',
       'kombu.transport.django',
       # 'grappelli',
       # 'chronograph',
       # 'registration', # Include the registration
    )
    

我尝试了什么?

  • 使用pip install django==1.8.2安装django。
  • 由于参考/usr/lib/python2.7/报告了错误,因此 我试过了:
    sudo pip install --install-option="--install-purelib=/usr/lib/python2.7/site-packages/" --ignore-installed django==1.8.2
  • 此外,当我对路径感到困惑时 /usr/local/lib/python2.7/dist-packages
    /usr/lib/python2.7/dist-packages/
    ~/.local/lib/python2.7/dist-packages 我逐一将django(1.8.2)安装到这些路径中 并行更新PYTHONPATH
  • 我在安装时遇到了错误。

有人可以帮助我吗?请解释错误的原因。

1 个答案:

答案 0 :(得分:4)

回溯显示/usr/lib/python2.7/django/__init__.py中发生错误,因此manage.py已清楚地找到您的Django安装。顺便说一句,使用虚拟环境而不是安装在/usr/lib/python2.7/site-packages/中会好得多。

问题似乎是kombu.transport.django中有INSTALLED_APPSDjango transport was removed from kombu in 4.0