4

I installed bootstrap4 with

$ pip install django-bootstrap4

It is being installed in this directory

C:\Users\trade\techpit-match-env\Lib\site-packages

Django seems to be looking at this directory

C:\Users\trade\Anaconda3\lib\site-packages\django

When I put 'bootstrap4' in the INSTALLED_APPS = ('bootstrap4') variable and then run

$ python manage.py runserver

I get this error

C:\Users\trade\techpit-match-env\Scripts\techpit>python manage.py runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x000001C4D8F65488>
Traceback (most recent call last):
  File "C:\Users\trade\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\trade\Anaconda3\lib\site-packages\django\core\management\commands\runserver.py", line 113, in inner_run
    autoreload.raise_last_exception()
  File "C:\Users\trade\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 248, in raise_last_exception
    raise _exception[1]
  File "C:\Users\trade\Anaconda3\lib\site-packages\django\core\management\__init__.py", line 327, in execute
    autoreload.check_errors(django.setup)()
  File "C:\Users\trade\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\trade\Anaconda3\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\trade\Anaconda3\lib\site-packages\django\apps\registry.py", line 89, in populate
    app_config = AppConfig.create(entry)
  File "C:\Users\trade\Anaconda3\lib\site-packages\django\apps\config.py", line 90, in create
    module = import_module(entry)
  File "C:\Users\trade\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'bootstrap4'

How can I resolve this error? I installed bootstrap4 in the django folder by using copy and paste and that did not work. Any help would be greatly appreciated.

Thank You!

Iguananaut
  • 21,810
  • 5
  • 50
  • 63
kenichiro
  • 43
  • 1
  • 1
  • 4
  • 1
    so techpit-match-env is a virtual environment you have set up? If you are running manage.py from the same virtual environment, the module will be found. Where you do python manage.py runserver, just try python, and then in the interactive session try import bootstrap4. If that doesn't work, your pip install is installing into the wrong environment. – Tim Richardson Dec 10 '19 at 10:23
  • 1
    Indeed, try searching stackoverflow for every other question containing "ModuleNotFound" and "pip". At least one of them will probably answer your problem but it's impossible to say since this is a problem with your computer's environment setup. As @TimRichardson wrote, you probably have more than one Python interpreter on your system and the `pip` you are calling is not necessarily the one for the `python` you're running. These days it's recommended to instead run `python -m pip` to ensure you're installing with the correct pip for the correct Python. – Iguananaut Dec 10 '19 at 10:48
  • It looks like `techpit-match-env` is a Conda env, so you need to ensure you've run `conda activate ` too. – Iguananaut Dec 10 '19 at 10:49
  • Yes I have set up techpit-match-env is a virtual environment.Python installed in this directory C:¥Users¥Kenichito¥Local¥Programs¥Python. So `python -m pip install bootstrap4` But bootstrap installed in this derectory C:¥Users¥Kenichito¥Anaconda3¥Lib¥site-packages. Is there no other way than using a Anaconda3? Tim Richardson, Iguananaut , Thank you very much I am grateful – kenichiro Dec 11 '19 at 05:07
  • I get similar error: "**ModuleNotFoundError: No module named 'bootstrap_modal_forms'**" – AnonymousUser Jun 21 '23 at 10:53

6 Answers6

11
python -m pip install bootstrap4

This locates pip on the python module path, thus ensuring that you install bootstrap4 in the same python environment that you use to run the manage.py commands. See this.

hundredrab
  • 357
  • 4
  • 10
  • Python installed in this directory C:¥Users¥Kenichito¥Local¥Programs¥Python. So `python -m pip install bootstrap4` But bootstrap installed in this derectory C:¥Users¥Kenichito¥Anaconda3¥Lib¥site-packages. Is there no other way than using a Anaconda3? hundredrab , Thank you very much I am grateful – kenichiro Dec 11 '19 at 05:09
  • @kenichiro, Which python does `python manage.py runserver` use? – hundredrab Dec 11 '19 at 05:25
  • hundredrab,I do python in this directory C:¥Users¥Kenichito¥Local¥Programs¥Python. Thank you very much I am grateful. I would like to send a huge thank you – kenichiro Dec 12 '19 at 08:32
  • That means you're anaconda environment isn't activated. You need to activate that environment. – hundredrab Dec 12 '19 at 08:58
  • hundredrab, Thank you again and again I'll try You are a great expert – kenichiro Dec 12 '19 at 10:23
  • on a AWS bitnami django server, I had to make sure to run the python install as `sudo`. Otherwise, it was still installing to the user profile. – glycoaddict May 15 '21 at 12:37
2

Check for a comma after 'bootstrap 4' in settings.py INSTALLED_APPS

Should be something like that:

INSTALLED_APPS = [
    # my apps
    'learning_logs',
    'users',
    # outside apps
    'bootstrap4',
    # django apps
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]
1

One way that worked for me was adding the Bootstrap CDN link directly to the base.html file. You can get the link from the Bootstrap site depending on the version you want to use. I hope this helps someone

0

I doing the same course, and I've got an answer. By steps what I checked:

  • proper virtual environment
  • proper lib
  • checking an doc of lib

And I found something interesting. This is an order of installed appps key INSTALLED_APPS.

This config key not work:

    INSTALLED_APPS = [
    # own applications
    'learning_logs',
    'users',
    # 3 party applications
    'bootstrap4'
    # django framework applications
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

But this work

INSTALLED_APPS = [
    # own applications
    'learning_logs',
    'users',
    # django framework applications
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # 3 party applications
    'bootstrap4'
]

Moving an 'bootstrap4' to the end fixes loading this lib.

Regards, Marcin

0

BOOTSTRAP4 MODULE NOT FIND ERROR in django (django-bootstrap4)

!! If you're using PyCharm and conda !! in pycharm -->

  • ctr-alt-s
  • project setting --> interpreter --> add package ("+")
  • search django-bootstrap4 in the searchtab
  • install the package

and it should work perfectly. don't forget to install it in APP (setting.py).

Niley
  • 1
-2

Bro for me work when i install django-bootstrap4 in environment i mean install it in ll_env but use all commend python -m pip install bootstrap4

Damian
  • 1
  • 1
    the wording does not help the opening post. I know you want to contribute, but make it in a way it is helpful and readable. Expect other people coming across this opening post and answer, please make it readable and use a mature text. – Jasper Lankhorst Dec 22 '22 at 13:54