【问题标题】:Converting Django project from Python 2 to Python 3: pip3 install django_comments NameError unicode将 Django 项目从 Python 2 转换为 Python 3:pip3 install django_comments NameError unicode
【发布时间】:2020-01-25 06:20:51
【问题描述】:

系统信息:64 位 OS-X,Python 3.7

我正在将一个 Django 网站从 Python 2 转换为 Python 3。为此,我在整个项目上运行了 2to3。然后我在 settings.py 的 INSTALL_APPS 中安装了所有必需的模块 - 除了一个:django_cmets。

(env) user:languages user$ pip3 install django_comments
Collecting django_comments
  Using cached https://files.pythonhosted.org/packages/c7/df/3a752f3e393b470087304dd47be6a4bad9867e7ec33963ff022d32143700/django-comments-1.0.0.b.tar.bz2
    ERROR: Command errored out with exit status 1:
     command: /Users/user/.../env/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/tb/vbtzyvv92hz6262qv7x8r8jh0000gn/T/pip-install-xjv_0ird/django-comments/setup.py'"'"'; __file__='"'"'/private/var/folders/tb/vbtzyvv92hz6262qv7x8r8jh0000gn/T/pip-install-xjv_0ird/django-comments/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
         cwd: /private/var/folders/tb/vbtzyvv92hz6262qv7x8r8jh0000gn/T/pip-install-xjv_0ird/django-comments/
    Complete output (7 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/tb/vbtzyvv92hz6262qv7x8r8jh0000gn/T/pip-install-xjv_0ird/django-comments/setup.py", line 12, in <module>
        version = get_version(),
      File "/private/var/folders/tb/vbtzyvv92hz6262qv7x8r8jh0000gn/T/pip-install-xjv_0ird/django-comments/django_comments/__init__.py", line 4, in get_version
        return u'.'.join(map(unicode, VERSION))
    NameError: name 'unicode' is not defined
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

我发现这个may be related to compatibility with Python 3 和一个潜在的解决方法是用str 替换unicode。但是,这是一个我想在 Python 3 中工作的模块,因为 Django 项目目前依赖于这个模块。它是否基本上被弃用了,除了自己改造它之外没有其他方法可以工作吗?谢谢。

【问题讨论】:

  • 我相信它仍在维护中。当您使用pip 将其更新到最新版本时会发生什么? django-contrib-comments.readthedocs.io/en/latest
  • django-cmets 似乎是一个 8 年前上传的库,此后从未修改过。它不可能适用于最新版本的 Python 或 Django。然而有许多评论库被维护,你应该使用其中之一:见this grid

标签: python django django-comments python-2to3


【解决方案1】:

我知道这有点晚了,但我相信 django_cmets 已移至 django-contrib-cmets。 Here 应该是最新的文档。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多