无法在从ubuntu导入的mac上运行django项目

时间:2015-06-03 13:25:03

标签: python django python-3.x django-models virtualenv

我的同事在Ubuntu上启动了一个django项目。我想在OS X Yosemite上运行相同的项目。我们都使用python3.4和以下包:

  • Django(1.8.2)
  • Pillow(2.8.1)
  • pip(7.0.3)
  • setuptools(17.0)
  • wheel(0.24.0)

我们都在虚拟环境中运行项目。

当我克隆项目时,我使用了

  

python manage.py syncdb

我得到了以下结果:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/user/Desktop/projectName/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/Users/user/Desktop/projectName/lib/python3.4/site-packages/django/core/management/__init__.py", line 312, in execute
    django.setup()
  File "/Users/user/Desktop/projectName/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/user/Desktop/projectName/lib/python3.4/site-packages/django/apps/registry.py", line 115, in populate
    app_config.ready()
  File "/Users/user/Desktop/projectName/lib/python3.4/site-packages/django/contrib/admin/apps.py", line 22, in ready
    self.module.autodiscover()
  File "/Users/user/Desktop/projectName/lib/python3.4/site-packages/django/contrib/admin/__init__.py", line 24, in autodiscover
    autodiscover_modules('admin', register_to=site)
  File "/Users/user/Desktop/projectName/lib/python3.4/site-packages/django/utils/module_loading.py", line 74, in autodiscover_modules
    import_module('%s.%s' % (app_config.name, module_to_search))
  File "/Users/user/Desktop/projectName/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/Users/user/Desktop/projectName/projectName/main/admin.py", line 3, in <module>
    from models import ContactLink, ContactPost, Personnel, WorkCategory, Service, Skill, Work, Customer
ImportError: No module named 'models'

我不知道为什么会发生这种情况并使用本网站和其他网站中描述的几种方法。 发生了什么事,为什么?

1 个答案:

答案 0 :(得分:2)

也会在您的Ubuntu安装上抛出错误。

您需要将line 3的{​​{1}}更改为:

projectName/main/admin.py

请注意from .models import ContactLink, ContactPost, Personnel, \ WorkCategory, Service, Skill, Work, Customer 部分中添加的点.。导入应该是相对的(假设所有这些模型都存在于同一个from .models应用程序中)。