How can I solve the issue: No module named 'simple_history'
Question:
I have my application and I would like to track the historical models for each modification in Django.
I have followed the instruction in this link: https://django-simple-history.readthedocs.io/en/latest/quick_start.html#install
However, I am getting the error ModuleNotFoundError: No module named ‘simple_history’
I uninstalled the package and reinstalled it but still getting the same error when I run the command python manage.py makemigrations
.
Here is my model.py
import uuid
from django.db import models
from django.contrib.auth.models import User
# from django import forms
from django.forms.widgets import RadioSelect
from ckeditor.fields import RichTextField
from django.utils.translation import ugettext_lazy as _
from django.urls import reverse
from random import randint
from simple_history.models import HistoricalRecords
class CourrierArrive(models.Model):
category_choice = (
('Entrant exterieur','Entrant exterieur'),
('Entrant locale ','Entrant locale'),
('Entrant locale interieur','Entrant locale interieur'),
)
statut = (
('Prioritaire','Prioritaire'),
('Rappel prévu','Rappel prévu'),
('Pour affectation','Pour affectation'),
('Pour signature','Pour signature'),
# ('Envoyer','Envoyé'),
('Annulé','Annulé'),
('A imprimer','A imprimer'),
('A archiver','A archiver'),
('A rappeler','A rappeler'),
('A Encours de validation','Encours de validation'),
('Attente','En attente'),
('Rejecte','Rejeté'),
('Terminé','Terminé'),
('A ranger','A ranger'),
('A enregistrer','A enregistrer'),
('Avis favorable','Avis favorable'),
('Avis défavorable','Avis défavorable'),
('Pour facturation','Avis facturation'),
('Pour de traitement','Encours de traitement'),
)
nature_courrier = (
('Lettre avec A/R', 'Lettre avec A/R'),
('Lettre simple','Lettre simple'),
('Lettre remise en main propre','Lettre remise en main propre'),
('Facture','Facture'),
)
confidentiel_choice = (
('1','Oui'),
('2','Non'),
)
classer = (('Oui','Oui'),
('Non','Non')
)
reference = models.CharField(max_length=20, blank=False, unique=True)
type_expediteur = models.CharField(choices=type_expediteur, max_length=50)
expediteur = models.ForeignKey(Expediteur,on_delete=models.CASCADE ,null=True)
destinataire = models.CharField(max_length=200, null=True, blank=False)
nature_courrier = models.CharField(max_length=50, choices=nature_courrier)
classer_sans_suite = models.CharField(max_length=3, choices=classer)
objet = models.CharField(max_length=500)
confidentiel = models.CharField(max_length=5, choices=confidentiel_choice)
type_courrier = models.CharField(choices=category_choice, max_length=50)
date_reception = models.DateField(auto_now_add=True)
date_modification = models.DateField(auto_now=True)
telephone = models.CharField(max_length=15)
adresse_1 = models.CharField(max_length=500, blank=False)
adresse_2 = models.CharField(max_length=500,blank=True)
email = models.CharField(max_length=50,blank=True)
nom_correspondant = models.CharField(max_length=200, blank=True)
telephone_correspondant = models.CharField(max_length=15, blank=True)
recepteur_courrier = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
statut = models.CharField(max_length=100, choices=statut)
# document_scanne = models.FileField(upload_to='courrier_arrive/%Y/%m/%d', blank=True)
commentaires = models.TextField(blank=True)
history = HistoricalRecords()
def __str__(self):
return self.reference
settings.py
file’s configuration
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'account',
'courriers',
'rolepermissions',
'crispy_forms',
'ckeditor',
'simple_history',
]
CRISPY_TEMPLATE_PACK = 'bootstrap4'
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
'simple_history.middleware.HistoryRequestMiddleware',
]
What can be the error, please?
pip freeze
results
asgiref==3.2.10
Django==3.1
django-ckeditor==6.0.0
django-cleanup==5.0.0
django-crispy-forms==1.9.2
django-debug-toolbar==2.2
django-discover-runner==1.0
django-js-asset==1.2.2
django-mathfilters==1.0.0
django-role-permissions==3.1.0
django-simple-history==2.8.0
django-tabination==0.4.0
fpdf==1.7.2
html5lib==1.1
Pillow==7.2.0
psycopg2==2.8.5
PyPDF2==1.26.0
pytz==2020.1
reportlab==3.5.47
six==1.15.0
sqlparse==0.3.1
Tether==0.1
webencodings==0.5.1
xhtml2pdf==0.2.4
Python version: Python 3.7.6
pip version: pip 20.2.2
Answers:
I solved the problem by deleting the virtual environment folder and create a new one. When I run the python manage.py makemigrations
command, it does not showing No module named ‘simple_history’ error. Now the issue has gone.
Thank you for your support.
It’s probably that you do not have venv activated.
To be sure use pip freeze
and check if simple_history
is installed.
Try with venvscriptsactivate
or with source venvscriptsactivate
I have my application and I would like to track the historical models for each modification in Django.
I have followed the instruction in this link: https://django-simple-history.readthedocs.io/en/latest/quick_start.html#install
However, I am getting the error ModuleNotFoundError: No module named ‘simple_history’
I uninstalled the package and reinstalled it but still getting the same error when I run the command python manage.py makemigrations
.
Here is my model.py
import uuid
from django.db import models
from django.contrib.auth.models import User
# from django import forms
from django.forms.widgets import RadioSelect
from ckeditor.fields import RichTextField
from django.utils.translation import ugettext_lazy as _
from django.urls import reverse
from random import randint
from simple_history.models import HistoricalRecords
class CourrierArrive(models.Model):
category_choice = (
('Entrant exterieur','Entrant exterieur'),
('Entrant locale ','Entrant locale'),
('Entrant locale interieur','Entrant locale interieur'),
)
statut = (
('Prioritaire','Prioritaire'),
('Rappel prévu','Rappel prévu'),
('Pour affectation','Pour affectation'),
('Pour signature','Pour signature'),
# ('Envoyer','Envoyé'),
('Annulé','Annulé'),
('A imprimer','A imprimer'),
('A archiver','A archiver'),
('A rappeler','A rappeler'),
('A Encours de validation','Encours de validation'),
('Attente','En attente'),
('Rejecte','Rejeté'),
('Terminé','Terminé'),
('A ranger','A ranger'),
('A enregistrer','A enregistrer'),
('Avis favorable','Avis favorable'),
('Avis défavorable','Avis défavorable'),
('Pour facturation','Avis facturation'),
('Pour de traitement','Encours de traitement'),
)
nature_courrier = (
('Lettre avec A/R', 'Lettre avec A/R'),
('Lettre simple','Lettre simple'),
('Lettre remise en main propre','Lettre remise en main propre'),
('Facture','Facture'),
)
confidentiel_choice = (
('1','Oui'),
('2','Non'),
)
classer = (('Oui','Oui'),
('Non','Non')
)
reference = models.CharField(max_length=20, blank=False, unique=True)
type_expediteur = models.CharField(choices=type_expediteur, max_length=50)
expediteur = models.ForeignKey(Expediteur,on_delete=models.CASCADE ,null=True)
destinataire = models.CharField(max_length=200, null=True, blank=False)
nature_courrier = models.CharField(max_length=50, choices=nature_courrier)
classer_sans_suite = models.CharField(max_length=3, choices=classer)
objet = models.CharField(max_length=500)
confidentiel = models.CharField(max_length=5, choices=confidentiel_choice)
type_courrier = models.CharField(choices=category_choice, max_length=50)
date_reception = models.DateField(auto_now_add=True)
date_modification = models.DateField(auto_now=True)
telephone = models.CharField(max_length=15)
adresse_1 = models.CharField(max_length=500, blank=False)
adresse_2 = models.CharField(max_length=500,blank=True)
email = models.CharField(max_length=50,blank=True)
nom_correspondant = models.CharField(max_length=200, blank=True)
telephone_correspondant = models.CharField(max_length=15, blank=True)
recepteur_courrier = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
statut = models.CharField(max_length=100, choices=statut)
# document_scanne = models.FileField(upload_to='courrier_arrive/%Y/%m/%d', blank=True)
commentaires = models.TextField(blank=True)
history = HistoricalRecords()
def __str__(self):
return self.reference
settings.py
file’s configuration
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'account',
'courriers',
'rolepermissions',
'crispy_forms',
'ckeditor',
'simple_history',
]
CRISPY_TEMPLATE_PACK = 'bootstrap4'
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
'simple_history.middleware.HistoryRequestMiddleware',
]
What can be the error, please?
pip freeze
results
asgiref==3.2.10
Django==3.1
django-ckeditor==6.0.0
django-cleanup==5.0.0
django-crispy-forms==1.9.2
django-debug-toolbar==2.2
django-discover-runner==1.0
django-js-asset==1.2.2
django-mathfilters==1.0.0
django-role-permissions==3.1.0
django-simple-history==2.8.0
django-tabination==0.4.0
fpdf==1.7.2
html5lib==1.1
Pillow==7.2.0
psycopg2==2.8.5
PyPDF2==1.26.0
pytz==2020.1
reportlab==3.5.47
six==1.15.0
sqlparse==0.3.1
Tether==0.1
webencodings==0.5.1
xhtml2pdf==0.2.4
Python version: Python 3.7.6
pip version: pip 20.2.2
I solved the problem by deleting the virtual environment folder and create a new one. When I run the python manage.py makemigrations
command, it does not showing No module named ‘simple_history’ error. Now the issue has gone.
Thank you for your support.
It’s probably that you do not have venv activated.
To be sure use pip freeze
and check if simple_history
is installed.
Try with venvscriptsactivate
or with source venvscriptsactivate