关于python:无法导入名称import_by_path

cannot import name import_by_path

请求方法:GET
请求网址:http://ec2-145-28-57-102.compute-1.amazonaws.com/reports/
Django版本:1.3.1
异常类型:ImportError
例外价值:

无法导入名称import_by_path

例外位置:/usr/lib/python2.6/site-packages/django/contrib/formtools/wizard/storage/init.py in,line 2
Python可执行文件:/ usr / bin / python
Python版本:2.6.6
Python路径:

[ '在/ var / WWW/堆栈/应用程序/项目/应用程序',
'/usr/lib64/python26.zip',
'/usr/lib64/python2.6',
'/usr/lib64/python2.6/plat-linux2',
'/usr/lib64/python2.6/lib-tk',
'/usr/lib64/python2.6/lib-old',
'/usr/lib64/python2.6/lib-dynload',
'/usr/lib64/python2.6/site-packages',
'/usr/lib/python2.6/site-packages',
'/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info',
'/无功/网络/堆栈/应用/']

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Traceback:
File"/usr/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
  101.                             request.path_info)
File"/usr/lib/python2.6/site-packages/django/core/urlresolvers.py" in resolve
  252.                     sub_match = pattern.resolve(new_path)
File"/usr/lib/python2.6/site-packages/django/core/urlresolvers.py" in resolve
  250.             for pattern in self.url_patterns:
File"/usr/lib/python2.6/site-packages/django/core/urlresolvers.py" in _get_url_patterns
  279.         patterns = getattr(self.urlconf_module,"urlpatterns", self.urlconf_module)
File"/usr/lib/python2.6/site-packages/django/core/urlresolvers.py" in _get_urlconf_module
  274.             self._urlconf_module = import_module(self.urlconf_name)
File"/usr/lib/python2.6/site-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)
File"/var/www/stacks/apps/project/apps/reports/urls.py" in <module>
  8. from views import (project_report, project_report_new, CustomReportList, delete_custom_report,
File"/var/www/stacks/apps/project/apps/reports/views.py" in <module>
  15. from forms import PROJECTReportForm, PROJECTReportFormNew, CrossCheckForm
File"/var/www/stacks/apps/project/apps/reports/forms.py" in <module>
  29. from django.contrib.formtools.wizard.views import SessionWizardView
File"/usr/lib/python2.6/site-packages/django/contrib/formtools/wizard/views.py" in <module>
  13. from django.contrib.formtools.wizard.storage import get_storage
File"/usr/lib/python2.6/site-packages/django/contrib/formtools/wizard/storage/__init__.py" in <module>
  2. from django.utils.module_loading import import_by_path

Exception Type: ImportError at /reports/
Exception Value: cannot import name import_by_path

异常类型:/ reports /的ImportError
异常值:无法导入名称import_by_path


文档声明import_by_path在Django 1.6中是新的,而问题提到了Django 1.3.1。 也许你安装了两个版本? 检查Python路径上的所有目录。


从Django 1.7中不推荐使用import_by_path
所以这实际上是因为检测到Django版本的方式存在错误:

1
2
3
4
    if django.get_version() >="1.7":
        from django.utils.module_loading import import_string
    else:
        from django.utils.module_loading import import_by_path as import_string

由于词法比较,不适用于Django> = 1.10。

需要编辑和分叉库或在本地环境中,您可以更改如下:

Edit site-packages/omnibus/management/commands/omnibusd.py

1
from django.utils.module_loading import import_string as import_by_path