django-nested-admin module not found

Hi,
I am new to Django. I am using Django 5.2. and python 3.12. I set up my virtual environment.
I want to have nested Inlinens in my admin interface so I Installed django-nested-admin using cmd (“pip install django-nested-admin”)
I also included it in the INSTALLED_APPS in settings.py:

INSTALLED_APPS = [
    'products',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'nested_admin',
]

Then I imported nested_admin in admin.py file, but I haven’t used it yet:

import nested_admin

when I run the server I get the following error:

Traceback (most recent call last):
  File "C:\Users\HP\AppData\Roaming\Python\Python312\site-packages\django\core\management\base.py", line 413, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\HP\AppData\Roaming\Python\Python312\site-packages\django\core\management\commands\runserver.py", line 75, in execute
    super().execute(*args, **options)
  File "C:\Users\HP\AppData\Roaming\Python\Python312\site-packages\django\core\management\base.py", line 459, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\HP\AppData\Roaming\Python\Python312\site-packages\django\core\management\commands\runserver.py", line 82, in handle
    if not settings.DEBUG and not settings.ALLOWED_HOSTS:
           ^^^^^^^^^^^^^^
  File "C:\Users\HP\AppData\Roaming\Python\Python312\site-packages\django\conf\__init__.py", line 81, in __getattr__
    self._setup(name)
  File "C:\Users\HP\AppData\Roaming\Python\Python312\site-packages\django\conf\__init__.py", line 68, in _setup
    self._wrapped = Settings(settings_module)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\HP\AppData\Roaming\Python\Python312\site-packages\django\conf\__init__.py", line 166, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\HP\AppData\Local\Programs\Python\Python312\Lib\importlib\__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "D:\Files\code\proper-house\properhouse\properhouse\settings.py", line 15, in <module>
    import nested_admin
ModuleNotFoundError: No module named 'nested_admin'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Files\code\proper-house\properhouse\manage.py", line 22, in <module>
    main()
  File "D:\Files\code\proper-house\properhouse\manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\HP\AppData\Roaming\Python\Python312\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line  
    utility.execute()
  File "C:\Users\HP\AppData\Roaming\Python\Python312\site-packages\django\core\management\__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\HP\AppData\Roaming\Python\Python312\site-packages\django\core\management\base.py", line 426, in run_from_argv
    connections.close_all()
  File "C:\Users\HP\AppData\Roaming\Python\Python312\site-packages\django\utils\connection.py", line 84, in close_all
    for conn in self.all(initialized_only=True):
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\HP\AppData\Roaming\Python\Python312\site-packages\django\utils\connection.py", line 78, in all
    for alias in self
                 ^^^^
  File "C:\Users\HP\AppData\Roaming\Python\Python312\site-packages\django\utils\connection.py", line 73, in __iter__
    return iter(self.settings)
                ^^^^^^^^^^^^^
  File "C:\Users\HP\AppData\Roaming\Python\Python312\site-packages\django\utils\functional.py", line 47, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
                                         ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\HP\AppData\Roaming\Python\Python312\site-packages\django\utils\connection.py", line 45, in settings
    self._settings = self.configure_settings(self._settings)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\HP\AppData\Roaming\Python\Python312\site-packages\django\db\utils.py", line 148, in configure_settings
    databases = super().configure_settings(databases)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\HP\AppData\Roaming\Python\Python312\site-packages\django\utils\connection.py", line 50, in configure_settings
    settings = getattr(django_settings, self.settings_name)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\HP\AppData\Roaming\Python\Python312\site-packages\django\conf\__init__.py", line 81, in __getattr__
    self._setup(name)
  File "C:\Users\HP\AppData\Roaming\Python\Python312\site-packages\django\conf\__init__.py", line 68, in _setup
    self._wrapped = Settings(settings_module)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\HP\AppData\Roaming\Python\Python312\site-packages\django\conf\__init__.py", line 166, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\HP\AppData\Local\Programs\Python\Python312\Lib\importlib\__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "D:\Files\code\proper-house\properhouse\properhouse\settings.py", line 15, in <module>
    import nested_admin
ModuleNotFoundError: No module named 'nested_admin'

I used pip list to check if the package have been installed:

django-nested-admin    4.1.1

Why the “nested-admin” module is not found?

It’s triggered by

in admin.py.

Verify package was installed in the same python version. (if you have multiple).

  1. Try below.
"### install the packages
(venv_name) user@host: pip3 install "package-name""

python - How to install a package inside virtualenv? - Stack Overflow

Packages should be installed in the virtual environment.

I was inside the virtual environment when i ran pip:

(.venv) D:\Files\code\proper-house\properhouse> pip install django-nested-admin

I also added the package to requirments.txt:

pip freeze > requirements.txt

requirments.txt

django-nested-admin==4.1.1

when I go to the .venv/Lib/site-packages there is a folder names: “django_nested_admin-4.1.1.dist-info”.

I also tried pip3 and got the following result:

(.venv) D:\Files\code\proper-house\properhouse>pip3 install djange-nested-admin
ERROR: Could not find a version that satisfies the requirement djange-nested-admin (from versions: none)
ERROR: No matching distribution found for djange-nested-admin

(.venv) D:\Files\code\proper-house\properhouse>pip install django-nested-admin
Requirement already satisfied: django-nested-admin in d:\files\code\proper-house\properhouse\.venv\lib\site-packages (4.1.1)
Requirement already satisfied: python-monkey-business>=1.0.0 in d:\files\code\proper-house\properhouse\.venv\lib\site-packages (from django-nested-admin) (1.1.0)

Is this happening because I am not using a linux terminal? because I have had a package before that wouldn’t allow me to use it without having a linux terminal (I had to install ubuntu terminal from WSL)

No.

To investigate this, In virtual environment, run below and show the output here.


which python

pip list -v


I’m not a expert on this ; but why your virtual environment name start with a dot?

Also,


Note that to activate your virtual environment on Widows, you will need to run the following code below (See this link to fully understand the differences between platforms):

 env/Scripts/activate.bat //In CMD
 env/Scripts/Activate.ps1 //In Powershel
(.venv) D:\Files\code\proper-house\properhouse>pip list -v
Package                Version     Location                                                       Installer
---------------------- ----------- -------------------------------------------------------------- ---------
asgiref                3.8.1       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
attrs                  25.3.0      D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
certifi                2025.1.31   D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
cffi                   1.17.1      D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
charset-normalizer     3.4.1       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
colorama               0.4.6       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
Django                 5.2         D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
django-nested-admin    4.1.1       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
factory_boy            3.3.3       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
Faker                  37.1.0      D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
h11                    0.14.0      D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
idna                   3.10        D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
inflection             0.5.1       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
iniconfig              2.1.0       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
Jinja2                 3.1.6       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
MarkupSafe             3.0.2       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
outcome                1.3.0.post0 D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
packaging              24.2        D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
pip                    25.0.1      D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
pluggy                 1.5.0       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
pycparser              2.22        D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
PySocks                1.7.1       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
pytest                 8.3.5       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
pytest-base-url        2.1.0       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
pytest-django          4.11.1      D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
pytest-factoryboy      2.7.0       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
pytest-html            4.1.1       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
pytest-metadata        3.1.1       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
pytest-selenium        4.1.0       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
pytest-variables       3.1.0       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
python-monkey-business 1.1.0       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
requests               2.32.3      D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
selenium               4.31.0      D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
sniffio                1.3.1       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
sortedcontainers       2.4.0       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
sqlparse               0.5.3       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
tenacity               9.1.2       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
trio                   0.29.0      D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
trio-websocket         0.12.2      D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
typing_extensions      4.13.2      D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
tzdata                 2025.2      D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
urllib3                2.4.0       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
websocket-client       1.8.0       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip
wsproto                1.2.0       D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages pip

(.venv) D:\Files\code\proper-house\properhouse>

At the time of creating that virtual environment I didn’t know how to create it so I looked up the command from the internet not knowing that this will be the name of my venv.

python -m venv .venv

also the only command that is working for me to activate the virtual environment is:

D:\Files\code\proper-house\properhouse>.venv\scripts\activate

(.venv) D:\Files\code\proper-house\properhouse>deactivate
D:\Files\code\proper-house\properhouse>.venv\scripts\actibate.bat
'.venv\scripts\actibate.bat' is not recognized as an internal or external command,
operable program or batch file.

D:\Files\code\proper-house\properhouse>

even using a “/” is not working

I tried installing the package in cmd (outside virtual environment) and the package worked perfectly:

C:\Users\HP>pip install django-nested-admin
Collecting django-nested-admin
  Using cached django_nested_admin-4.1.1-py3-none-any.whl.metadata (6.4 kB)
Collecting python-monkey-business>=1.0.0 (from django-nested-admin)
  Using cached python_monkey_business-1.1.0-py2.py3-none-any.whl.metadata (2.8 kB)
Using cached django_nested_admin-4.1.1-py3-none-any.whl (465 kB)
Using cached python_monkey_business-1.1.0-py2.py3-none-any.whl (4.7 kB)
Installing collected packages: python-monkey-business, django-nested-admin
Successfully installed django-nested-admin-4.1.1 python-monkey-business-1.1.0

[notice] A new release of pip is available: 24.0 -> 25.0.1
[notice] To update, run: python.exe -m pip install --upgrade pip

C:\Users\HP>py
Python 3.12.3 (tags/v3.12.3:f6650f9, Apr  9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import nested_admin
>>>
# admin.py
from django.contrib import admin
import nested_admin
from .models import Category, Subcategory, Product

class ProductInline(nested_admin.NestedTabularInline):
    model = Product
    extra = 1

class SubcategoryInline(nested_admin.NestedStackedInline):
    model = Subcategory
    inlines = [ProductInline]
    extra = 1

@admin.register(Category)
class CategoryAdmin(nested_admin.NestedModelAdmin):
    inlines = [SubcategoryInline]

then I uninstalled it from outside the virtual environment and I’ am back to the first error. I have installed multiple packages before inside venv like django, pytest, django-pytest, etc and they all work fine but this one is not for some reason.

Are you saying when you uninstall it outside the virtual environment, error appear inside the environment?
Or when you tested it works outside but doesn’t work inside?

I installed the package outside venv then I tried running the server (which is inside the venv) and it worked fine, then I uninstall it outside the virtual environment, error appear inside the environment.

I haven’t tested it outside the environment. It worked inside venv only when i had the package installed outside venv (on the main python installation not another venv)

Try 1,

then 2 - if not worked,

then 3.

It would imply that your virtual environment is not activated correctly.(100%).

1) Testing

Try using pip -V (notice capital V)

If you are running the virtual env. it’ll show the path to the env.'s location.

pip -V

Tests

Question

What are the results of

which python

and

import sys
print(sys.path())

.

2) Fixing

Activate environment with . venv/Scripts/activate

You should be in the same folder as .venv folder.

3) Moving

Can’t guarantee about this.
But try moving the virtual environment to a new folder as below.

  1. Creat a new folder my_venv
  2. Copy and paste all the project files from old environment
  3. Activate environment with my_venv/Scripts/activate
  4. Install requirements

I ran the command from CMD:

Microsoft Windows [Version 10.0.26100.3775]
(c) Microsoft Corporation. All rights reserved.

C:\Users\HP>pip -V
pip 24.0 from C:\Users\HP\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip (python 3.12)

C:\Users\HP>

I also ran it from the cmd terminal in my IDE:

(.venv) D:\Files\code\proper-house\properhouse>pip -V
pip 25.0.1 from D:\Files\code\proper-house\properhouse\.venv\Lib\site-packages\pip (python 3.12)

(.venv) D:\Files\code\proper-house\properhouse>

maybe it is showing this because my venv is in the D drive not the C drive.

for wich “which python” I don’t know what is that, I tried running it outputs the following:

(.venv) D:\Files\code\proper-house\properhouse>which python
'which' is not recognized as an internal or external command,
operable program or batch file.

I also tried this command:

(.venv) D:\Files\code\proper-house\properhouse>py               
Python 3.12.3 (tags/v3.12.3:f6650f9, Apr  9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.path())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'list' object is not callable
>>>
(.venv) D:\Files\code\proper-house\properhouse>deactivate
D:\Files\code\proper-house\properhouse>. venv/Scripts/activate
'.' is not recognized as an internal or external command,
operable program or batch file.

D:\Files\code\proper-house\properhouse>
D:\Files\code\proper-house\properhouse>.venv\Scripts\activate

(.venv) D:\Files\code\proper-house\properhouse>

Maybe my file structure is the problem here?

You are right because I also just realized that all the packages that where working before where actually installed both outside and inside venv

If my file structure is not the problem then I think I have to remove this virtual environment and setup another one.

All the commands you run in cmd/shell without inside an activated virtual environment, run globally (with global python and packages).

If activated correctly all the commands will run inside the virtual environment automatically. No need to navigate folders.

What is important is activating the environment and

run all the commands inside activated cmd/shell.

Django project should be in the virtual environment. Otherwise what’s the point?.

Once you have come up with a suitable name for your Django project, like mine: my_tennis_club, navigate to where in the file system you want to store the

(in the virtual environment),

I will navigate to the myworld folder, and run this command in the command prompt:

django_create_project



Look here how to create virtual environment.

django_create_virtual_environment.

  1. Environment creation.
python -m venv myworld

Result folder structure.


myworld
  Include
  Lib
  Scripts
  .gitignore
  pyvenv.cfg
  1. Activation.

myworld\Scripts\activate.bat

If activated correctly, path should look like this.

(myworld) C:\Users\Your Name>

All the commands, including django project creation, migration, runserver, pip install should run inside virtual environment.

While it’s activated.

1 Like

Is everything fixed?.

Yes It is working, the problem was that the venv was inside the django project file, so I just deleted it and created another one outside.

To test this I deleted the package from my main python installation and installed it inside the venv and it is working, also I don’t have a bunch of unnecessary packages inside my requirments.txt that was taken from my main python installation.

also I remembered why my venv name starts with a dot, its because I created it using the IDE interface at that time because for some reason when I create it using terminal I don’t see the venv file so I thought that the command didn’t work

Thanks man for the help!

1 Like

Happy to hear you got it to work. :rocket: