【问题标题】:NameError: name 'six' is not defined. six in not working with django and leafletNameError:名称“六”未定义。六个不使用 django 和传单
【发布时间】:2020-06-06 23:39:08
【问题描述】:

我的传单配置需要一些帮助。 由于我将传单添加到我的 django-3.04 项目中,因此在运行服务器时出现此错误。

      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/src/django-leaflet/leaflet/__init__.py", line 80, in <module>
    if DEFAULT_PRECISION is not None and not (isinstance(DEFAULT_PRECISION, six.integer_types) and (4 <= DEFAULT_PRECISION <= 12)):
NameError: name 'six' is not defined  

我安装了六个并将其添加到 settings.py 文件中,但仍然出现同样的错误。我不知道还能去哪里寻找和做什么。 :/

【问题讨论】:

标签: python django six


【解决方案1】:

我遵循了这个答案,它终于奏效了。

  • 转至https://pypi.org/project/six/#files
  • 下载“six-1.14.0.tar.gz (33.9 kB)”
  • 解压缩,将“six.py”复制并粘贴到您的源目录中。
  • 将“六”模块导入您的源代码(导入六)
  • 运行源脚本。

https://stackoverflow.com/a/61327529/8571945

谢谢大家

【讨论】:

    【解决方案2】:

    Django 曾经与six 一起打包,但由于完全删除了对 Python 2 的支持,3.0 版已将其删除:https://docs.djangoproject.com/en/3.0/releases/3.0/#removed-private-python-2-compatibility-apis

    目前,如果您需要django-leaflet,您可能必须继续使用 Django 2.2 版。但是,看起来他们正在支持 Django 3。在撰写本文时,20 天前的最后一次提交是 Drop support for Python 2:

    https://github.com/makinacorpus/django-leaflet/commit/844887affe607d3f115920c862f8ea2b45e19ed8

    可能值得尝试将此提交安装到您的虚拟环境中,看看它是否能解决问题:

    pip install git+https://github.com/makinacorpus/django-leaflet.git@844887affe607d3f115920c862f8ea2b45e19ed8

    我尝试将其转换为venv,但它似乎不再需要six

    不管怎样,看起来他们正在为 Django 3.0 发布一个版本,但 PyPI 还没有为 pip install 提供它。祝你好运!

    【讨论】:

    • 非常感谢。我试过了,但也没有用。它一定与路径或环境变量有关,但我确实尝试了另一种方法,将 Six.py 文件添加到我的传单文件夹中,它终于奏效了。
    猜你喜欢
    • 2022-10-16
    • 2018-07-14
    • 2017-12-25
    • 2021-07-17
    • 2012-05-13
    • 2017-08-17
    • 2020-02-24
    • 2021-04-14
    • 2020-08-17
    相关资源
    最近更新 更多