0

i need some help with my leaflet config. i'm getting this error when running the server since i added leaflet to my django-3.04 project.

      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  

I installed six and add it to the settings.py file but still getting that same error. i don't know where else to look and what to do. :/

IvanSanchez
  • 18,272
  • 3
  • 30
  • 45
Romain BOBOE
  • 367
  • 3
  • 10
  • You either need to import or install "six" package - https://stackoverflow.com/questions/13967428/importerror-no-module-named-six – Ben Jun 06 '20 at 23:49
  • Clearly it's either not been imported or is not in the pythonpath. Can you try importing `os` first and checking the enviroment variables for the paths checked? – J.Warren Jun 07 '20 at 00:13
  • `six` used to be included with Django, but was removed in version 3.0: https://docs.djangoproject.com/en/3.0/releases/3.0/#removed-private-python-2-compatibility-apis Packages need to upgrade to remove Python 2 compatibility APIs. See my answer below. – FlipperPA Jun 07 '20 at 01:31

2 Answers2

1

i followed this answer and it finally worked.

  • go to https://pypi.org/project/six/#files
  • download "six-1.14.0.tar.gz (33.9 kB)"
  • unzip it, copy and paste "six.py" into your source directory.
  • import "six" module into your source code (import six)
  • run source script.

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

Thanks guys

Romain BOBOE
  • 367
  • 3
  • 10
0

Django used to come packaged with six, but version 3.0 has dropped it since Python 2 support has been completely removed: https://docs.djangoproject.com/en/3.0/releases/3.0/#removed-private-python-2-compatibility-apis

For now, if you need django-leaflet, you may have to stay on Django version 2.2. However, it looks like they're in the process of supporting Django 3. As of this writing, the last commit from 20 days ago is, Drop support for Python 2:

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

It may be worth trying an install from this commit into your virtual environment to see if it solves the issue:

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

I attempted it into a venv, and it didn't seem to require six any more.

Either way, it looks like they're working on a release for Django 3.0, it just isn't available from PyPI for pip install quite yet. Good luck!

FlipperPA
  • 13,607
  • 4
  • 39
  • 71
  • 1
    Thanks very much. i tried that but it didn't work either. it must be something about the paths or the environment variables but i did try an other way by adding six.py file into my leaflet folder and it finally worked. – Romain BOBOE Jun 07 '20 at 11:05