python - 导入错误/无法导入名称截断器

标签 python django makefile virtualenv buildout

所以我设置了使用 django 1.3 和 zc.buildout 的旧 python 项目。当我运行服务器时,出现以下错误:

这是完整的堆栈跟踪:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/

Django Version: 1.3
Python Version: 2.7.6
Installed Applications:
['filebrowser',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.sitemaps',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'south',
 'sugar',
 'registration',
 'webtopay',
 'pagination',
 'rest_framework',
 'rest_framework.authtoken',
 'mptt',
 'feincms',
 'feincms.module.page',
 'esavadai',
 'esavadai.documents',
 'esavadai.users',
 'esavadai.bookmarks',
 'esavadai.services',
 'esavadai.statistics',
 'esavadai.orders',
 'esavadai.emails',
 'debug_toolbar',
 'django_extensions',
 'test_utils']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.middleware.csrf.CsrfResponseMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'pagination.middleware.PaginationMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware')


Traceback:
File "/home/marijus/workspace/esavadai/eggs/Django-1.3-py2.7.egg/django/core/handlers/base.py" in get_response
  89.                     response = middleware_method(request)
File "/home/marijus/workspace/esavadai/eggs/Django-1.3-py2.7.egg/django/utils/importlib.py" in import_module
  35.     __import__(name)
File "/home/marijus/workspace/esavadai/project/esavadai/urls.py" in <module>
  8. admin.autodiscover()
File "/home/marijus/workspace/esavadai/eggs/Django-1.3-py2.7.egg/django/contrib/admin/__init__.py" in autodiscover
  26.             import_module('%s.admin' % app)
File "/home/marijus/workspace/esavadai/eggs/Django-1.3-py2.7.egg/django/utils/importlib.py" in import_module
  35.     __import__(name)
File "/home/marijus/workspace/esavadai/eggs/django_extensions-1.3.9-py2.7.egg/django_extensions/admin/__init__.py" in <module>
  23. from django_extensions.admin.widgets import ForeignKeySearchInput
File "/home/marijus/workspace/esavadai/eggs/django_extensions-1.3.9-py2.7.egg/django_extensions/admin/widgets.py" in <module>
  7. from django.utils.text import Truncator

Exception Type: ImportError at /
Exception Value: cannot import name Truncator

这是我的构建文件:

[buildout]
parts =
    apacheconf
    production.py
    my.cnf
    mkdir
    django
#   scribd-patch
    jquery-ui
    tinymce

eggs =
    PIL
    South
    django
    django-annoying
    django-sugar
    python-scribd
    django-mptt
    django-filebrowser-no-grappelli
    django-webtopay
    django-pagination
    django-registration
    feincms
    mock
    simplejson
    djangorestframework
    djangorestframework-csv
    markdown

extra-paths = project


allowed-eggs-from-site-packages =
    PIL
    setuptools
    distribute

extensions = mr.developer
sources = sources
sources-dir = parts
auto-checkout = *

download-cache = cache

versions = versions

servername = www.myproject.com
serveradmin = <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8dece9e0e4e3cde0f4fdffe2e7e8eef9a3eee2e0" rel="noreferrer noopener nofollow">[email protected]</a>

[sources]
# my.package = svn http://example.com/svn/my.package/trunk
# some.other.package = git git://example.com/git/some.other.package.git
# bzr.package = bzr bzr+ssh://bazaar.launchpad.net/~user/project/branch/
python-scribd = svn http://python-scribd.googlecode.com/svn/trunk
django-annoying = hg https://bitbucket.org/sirex/django-annoying
django-sugar = git git://github.com/montylounge/django-sugar.git
django-filebrowser-no-grappelli = git git://github.com/wardi/django-filebrowser-no-grappelli.git
django-webtopay = git git://github.com/Motiejus/django-webtopay.git

[versions]
South = 0.7.3
django = 1.3
django-mptt = 0.4.2
django-pagination = 1.0.7
django-registration = 0.8
feincms = 1.4.2
mock = 0.8.0
simplejson = 2.2.1
djangorestframework = 2.2.7
markdown = 2.3.1
django-debug-toolbar = 0.9.4

[django]
recipe = djangorecipe
project = project
settings = production
eggs = ${buildout:eggs}
extra-paths = ${buildout:extra-paths}
wsgi = true
wsgilog = ${buildout:directory}/var/log/wsgi.log

[mkdir]
recipe = z3c.recipe.mkdir
paths =
    ${buildout:directory}/var/htdocs/static
    ${buildout:directory}/var/log

[apacheconf]
recipe = collective.recipe.template
input = ${buildout:directory}/etc/apache.conf.in
output = ${buildout:directory}/etc/apache.conf

[production.py]
recipe = collective.recipe.template
input = ${buildout:directory}/etc/production.py.in
output = ${buildout:directory}/etc/production.py

[my.cnf]
recipe = collective.recipe.template
input = ${buildout:directory}/etc/my.cnf.in
output = ${buildout:directory}/etc/my.cnf

[scribd-patch]
recipe = collective.recipe.patch
path = parts/python-scribd/scribd/
patches = patches/scribd-issue-3.diff

[jquery-ui]
recipe = hexagonit.recipe.download
url = http://jquery-ui.googlecode.com/files/jquery-ui-1.8.19.zip
destination = ${buildout:directory}/var/vendor-staticfiles
ignore-existing = true
excludes =
    index.html
    development-bundle/*

[tinymce]
recipe = hexagonit.recipe.download
url = https://github.com/tinymce/tinymce/archive/3.4.4.zip
destination = ${buildout:directory}/var/vendor-staticfiles
ignore-existing = true
excludes =
    tinymce/changelog.txt
    examples/*
strip-top-level-dir = true

据我所知,django.utils.text 中的 Truncator 类不在 django 1.3 中。如果我不得不猜测某个模块,其版本未在 buildout 中指定,则使用此类,但当该项目在 django 1.3 上构建时则没有指定。

我说得对吗?是否 - 我在这里有什么选择?

最佳答案

Truncator 类已添加到 Django 1.4 中。显然您安装的 django-extensions 版本需要 Django 1.4 或更高版本;正是该包尝试进行此导入。

您必须找到适用于您的 Django 1.3 设置的该软件包的旧版本。

查看 django-extensions GitHub 存储库,您可以看到它们 removed compatibility for older Django versions去年11月。 GitHub UI 向我们显示,包含该提交的最早标签是 1.3,因此之前的版本应该仍然有效。根据 GitHub 标签列表和 django-extensions PyPI information,该版本似乎是 2.5。 .

将该包固定在您的版本部分:

[versions]
# ...

django-extensions = 1.2.5

关于python - 导入错误/无法导入名称截断器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25064509/

相关文章:

python - django apache mod-wsgi 挂起从 .so 文件导入 python 模块

makefile - 如何在makefile中将include指令用于特定目标

c++ - 模板函数在编译期间被报告为 "undefined reference"

python - 为什么 pandas df.loc + lambda 不起作用?

python - 我应该使用什么模型字段类型来存储多个 long 类型?

django - 使用管理员创建用户时向 django 添加所需的电子邮件字段

python - 在 pip install 上运行 Makefile

python - 是什么导致我的 Python C 扩展崩溃?

python - 从 Numpy 数组的索引中采样的有效方法?

python - 将 Google Picasa API 与 Python 结合使用