Quickly fix “No module named ‘bootstrap5′” ModuleNotFoundError in Django
Where Django provides out-of-the-box functionality to create modern web applications, Bootstrap focuses on creating responsive and attractive web pages. With that, you can blend the two technologies to produce visually appealing and functional websites without compromising on development time.
While there are articles that show you how to integrate Bootstrap into your Django project, you are likely to face an issue or misconfiguration that may give you a headache figuring out.
One of the mistakes you can make when integrating your Django project with Bootstrap 5 is to miss installing the package correctly. If you do, you are likely to face ModuleNotFoundError: No module named ‘bootstrap5’ error in Django.
The error is just Django informing you that it cannot locate the package used to integrate Bootstrap into your Django project.
First, let’s look at the couple of reasons as to why you may get No module named 'boostrap5'
Why you’re getting ModuleNotFoundError: No module named ‘bootstrap5’ in Django
Here are things you need to check you have accomplished if you are getting ModuleNotFoundError: No module named ‘bootstrap5’ error in Django:
- Check you have installed the correct package for loading Bootstrap 5
- Check you have installed django-bootstrap-v5 in your virtual environment
- Check you have activated the correct Python virtual environment
Check you have installed the correct package that loads Bootstrap 5 into your project
The common mistake I make and seen other developers makes is installing the package for loading Bootstrap 5 in your Django project while using a wrong app name in the setting.py file.
The correct package names for loading Bootstrap 5 into your Django project are django-bootstrap-v5 and django-bootstrap5.
The common mistake is to install django-bootstrap5 package instead of django-bootstrap-v5, where you have the app name specified in your settings.py file as bootstrap5.
django-bootstrap5 and django-bootstrap-v5 are valid packages you can use to blend your Django project with Bootstrap 5.
Each of these packages are different package names that are installed differently.
django-bootstrap-v5 can be installed using the following command
pip install django-bootstrap-v5
django-bootstrap5 can be installed using the following command
pip install django-bootstrap5
Also, when it comes to specifying the app names in your settings.py file, each app should have a unique app naming.
django-bootstrap-v5 is added to list of
INSTALLED_APPS
using the following code:INSTALLED_APPS = ( # ... "bootstrap5", # ... )
django-bootstrap5 is added to list of
INSTALLED_APPS
using the following code:INSTALLED_APPS = ( # ... "django_bootstrap5", # ... )
NOTE the differences
So make sure that you have the correct package and its associated app name in your settings.py file.
For ModuleNotFoundError: No module named ‘bootstrap5’ error, it means:
- You need to install django-bootstrap-v5 package instead of django-bootstrap5
pip install django-bootstrap-v5
Then, in your settings.py file, add bootstrap5
to INSTALLED_APPS
.
INSTALLED_APPS = (
# ...
"bootstrap5",
# ...
)
Make sure you have this:
django-bootstrap-v5 not installed in your activated virtual environment
You may have the correct configuration settings but missing to install django-bootstrap-v5 in your activated Python virtual environment.
To fix the ModuleNotFound exception, open the terminal window and type the following to activate Python virtual environment.
On Mac/Linux use the following command:
source path-to-env/bin/activate
On Windows, use the command:
path-to-env\Scripts\activate.bat
After activating the virtual environment, you will notice the name of the virtual environment will appear at the beginning of the prompt, install django-bootstrap-v5 package
pip install django-bootstrap-v5
You have not activated the correct virtual environment
If you have multiple Python virtual environment on your system, check to ensure you are using the virtual environment with the django-bootstrap-v5 installed.
With the virtual environment active, you can check if the environment has django-bootstrap-v5 package by running the following command:
pip freeze
In the list of packages, you should be able to pinpoint django-bootstrap-v5
.
Otherwise, if it is not there, you are using the incorrect virtual environment— activate the correct Python virtual environment that has django-bootstrap-v5 installed.
How to fix ModuleNotFoundError: No module named ‘bootstrap5’
To fix ModuleNotFoundError: No module named ‘bootstrap5’ in Django, follow these steps:
Step 1: Activate the correct virtual environment for your Django project
source path-to-env/bin/activate
Step 2: Ensure you have installed django-bootstrap-v5 package.
Otherwise, install the package to load Bootstrap 5
pip install django-bootstrap-v5
That should fix the error.
How to add Bootstrap 5 to Django the correct way?
The best way to use bootstrap in Django is to use the django-bootstrap5 package which saves you time, effort, and complexities of including Django in your project and leveraging its features.
For more information on how to blend your Django project with Bootstrap 5, check out the article I have written on how to use Bootstrap 5 with your Django project the right way.
Related Question
What is the difference between django-bootstrap5 and django-bootstrap-v5?
Both django-bootstrap5 and django-bootstrap-v5 can be used to load Bootstrap 5 in your Django project. These packages make it easier for developers to use Bootstrap in their Django projects by:
- Including all the CSS and Javascript files required to use Bootstrap 5 in a Django project
- Provide a set of template tags to be used to include Bootstrap components such as forms in your Django templates
- Allow you to use Bootstrap classes in Django templates
Key differences between django-bootstrap5 and django-bootstrap-v5 are:
django-bootstrap5 | django-bootstrap-v5 |
---|---|
Installed using the following command:pip install django-bootstrap5 | Installed using the following command:pip install django-bootstrap-v5 |
INSTALLED_APPS configuration in settings.py look like this:INSTALLED_APPS = ( # ... "django_bootstrap5", # ... ) | INSTALLED_APPS configuration in settings.py look like this:INSTALLED_APPS = ( # ... "bootstrap5", # ... ) |
More actively maintained |
Thanks a lot. I ran into that installing bootstrap5 through conda and you provided all of the information I needed!