Skip to content

Instantly share code, notes, and snippets.

@nullx5
Last active February 20, 2025 07:09
Show Gist options
  • Save nullx5/67436fd28ce982fd5f60b8bd007c98f9 to your computer and use it in GitHub Desktop.
Save nullx5/67436fd28ce982fd5f60b8bd007c98f9 to your computer and use it in GitHub Desktop.

django1.8 con python3.5.10 mediante pyenv

Django 1.8 con Python 3.10, ya no es compatible.

Causa del error
En Django 1.8, el código intenta importar Mapping desde collections:

from collections import Mapping, OrderedDict

Sin embargo, en Python 3.10, Mapping fue movido a collections.abc, por lo que el import correcto debería ser:

from collections.abc import Mapping, OrderedDict

Dado que Django 1.8 no se ha actualizado para reflejar este cambio, falla al ejecutarse en versiones modernas de Python.

opciones:

  • usar una version de python antigua
  • usar una version mas nueva de django
  • tratar de arreglar el codigo 👨🏻‍💻🤪

Django 1.8 funciona bien con Python 2.7, 3.4 o 3.5.

Django 1.8 es muy antiguo (2015) y ya no recibe soporte.

Python 3.5 está obsoleto y su soporte terminó en 2020.

sudo apt-get update; sudo apt-get install make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev ca-certificates


curl -fsSL https://pyenv.run | bash

nvim .zshrc
    export PYENV_ROOT="$HOME/.pyenv"
    [[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
    eval "$(pyenv init - bash)"

    eval "$(pyenv virtualenv-init -)"

    reiniciar el shell

pyenv install --list |less

pyenv install 3.5.10

pyenv versions

pyenv virtualenv 3.5.10 django1.8 # /home/blessed/.pyenv/versions/3.5.10/envs/django1.8

pyenv activate django1.8




/home/blessed/.pyenv/versions/3.5.10/bin/python3.5 -m pip install django==1.8

/home/blessed/.pyenv/versions/3.5.10/bin/python3.5 -m pip install django==1.8 --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org

which django-admin

/home/blessed/.pyenv/versions/3.5.10/bin/django-admin startproject miproyecto

cd miproyecto

/home/blessed/.pyenv/versions/3.5.10/bin/python3.5 manage.py runserver

hasta aqui parece que funciona.

@nullx5
Copy link
Author

nullx5 commented Feb 20, 2025

Tratando de parchar los errores para que django1.8 corra con python 3.10

django-admin startproject miproyecto

ERROR:

File "/home/blessed/.local/lib/python3.10/site-packages/django/db/models/sql/query.py", line 11, in <module>
    from collections.abc import Mapping, OrderedDict
ImportError: cannot import name 'OrderedDict' from 'collections.abc' (/usr/lib/python3.10/collections/abc.py)

SOLUCION:

nvim /home/blessed/.local/lib/python3.10/site-packages/django/db/models/sql/query.py

Cambia:

from collections.abc import Mapping, OrderedDict

por :

from collections.abc import Mapping
from collections import OrderedDict

python3 manage.py runserver

ERROR:

File "/home/blessed/.local/lib/python3.10/site-packages/django/core/paginator.py", line 106, in <module>
    class Page(collections.Sequence):
AttributeError: module 'collections' has no attribute 'Sequence'

SOLUCION:

nvim /home/blessed/.local/lib/python3.10/site-packages/django/core/paginator.py

Cambia:

import collections
class Page(collections.Sequence):

por :

import collections.abc
class Page(collections.abc.Sequence):

python3 manage.py runserver

ERROR:

File "/home/blessed/.local/lib/python3.10/site-packages/django/db/models/fields/__init__.py", line 855, in _get_choices
    if isinstance(self._choices, collections.Iterator):
AttributeError: module 'collections' has no attribute 'Iterator'

SOLUCION:

nvim /home/blessed/.local/lib/python3.10/site-packages/django/db/models/fields/__init__.py

Cambia:

import collections
if isinstance(self._choices, collections.Iterator):

Por:

import collections.abc
if isinstance(self._choices, collections.abc.Iterator):

Aparentemente funciona. 🤪

Recomendación

Django 1.8 es incompatible con Python 3.10. Aunque puedes seguir parchando errores, lo mejor sería:

  • Usar Python 3.5 si realmente necesitas Django 1.8.

  • Actualizar Django a una versión compatible con Python 3.10 (como Django 3.x o 4.x).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment