Advanced Tutorial :How to write reusable apps

I have followed the Advanced tutorial named : “How to write a reusable apps” .
All went fine until the “Using your own package” section where iam stuck at the step 2 .

So my problem is that i can’t launch the server properly .
I have a error message that says . ModuleNotFound error : No module named “django_polls.”
I have also a virtual env installed in the same file that my project.

How it is possible to run the server with the app outside of the project directory ?
Here is the link toward the tutorial .

Did you successfully create the django_polls package?
(You have a django-polls-0.1.tar.gz file?)

Did you successfully install it?

Does a pip list show django_polls?

Exactly what commands did you use during this step of the tutorial?

What exactly do you mean by this? (virtual environments aren’t “installed in files”)

Is the virtual environment active when you did the pip install?

The components of your project are Python modules. A Python module can be imported from any directory that is part of the default search path, along with those directories specified in PYTHONPATH.

Yes it shows on a pip list
and i can see it in mysite>env>Lib

From django_polls directory
python -m pip install polls/dist/django-polls-0.1.tar.gz


yes (env) appear on my terminal.

After doing the pip install and verifying that it worked, how are you running your application?

I do it like this : python runserver

And that’s with the package installed, the virtual environment activated, and the package in your INSTALLED_APPS?


That answers the 3rd question of my previous reply, what about the first two?

Are you running runserver with that virtual environment activated? Is your package installed in that virtual environment?

Yes , i try to run runserver with the virtual environment activated (env).

Yes the package is installed in env>Lib>site-package.

Unfortunately, I can’t recreate the issue you’re encountering from the information you’re providing.

Try activating the virtual environment from the command line and running the Python (not Django) shell. Then import django_polls

Also, please report the versions of Python and Django you are using in your venv. (The output from python -V and pip list.)

So when i import django from my python shell (with my venv running) i have the message ModuleNotFoundError : No django module named ‘django_polls’.

The python version when i enter the command python-V is : 3.10.1.
Here is a screenshot of the pip list .

Sorry, I misread the docs for this. The module name is polls, not django_polls. (See the green notes box for the README.rst file)
Try import polls.

Same result as the previous attempt

Ok, so this indicates something is wrong with:

  • Your directory structure of your django-polls directory
  • One of the or setup.cfg files.
  • The commands you used to create or install the package.
  • Your virtual environment
  • Your use of the virtual environment.

So the next things to check would be your django-polls directory structure and the two configuration files.

Here is a screenshot of the django_polls directory structure .

Here is screeshots for the two config files and setup.cfg .


From the docs at Packaging your app

  1. First, create a parent directory for polls , outside of your Django project. Call this directory django-polls .

Notice they specify the directory name should be django-polls, not django_polls.

Indeed , i changed the directory’s name but the result is still not satisfactory.
I want to thank you for your help anyway.
Really appreciate it

After changing the directory name, please post each command you entered after that to rebuild and redeploy your module.