ihmemies ihmemies - 6 months ago 80
Python Question

Django ImportError: no module named 'shop'

I tried searching for answers to this problem but, at least with my eyeballs, I did not find the same problem anywhere else.

I started doing a django project from the book "Django by example'. I've been using a virtual environment. Following the book, I downloaded Django 1.8.6.

I added the app 'shop' into the list of apps in the settings file.


I created the models according to the book.

Then I tried "makingmigrations" but it gives me ImportError. Like this:

(myenv) C:\Users\Subject\djangoshop>python manage.py runserver --traceback
Unhandled exception in thread started by <function check_errors.<locals>.wrapper
at 0x0000000003EEEB70>
Traceback (most recent call last):
File "C:\Users\Subject\djangoshop\myenv\lib\site-packages\django\utils\autorel
oad.py", line 229, in wrapper
fn(*args, **kwargs)
File "C:\Users\Subject\djangoshop\myenv\lib\site-packages\django\core\manageme
nt\commands\runserver.py", line 107, in inner_run
File "C:\Users\Subject\djangoshop\myenv\lib\site-packages\django\utils\autorel
oad.py", line 252, in raise_last_exception
File "C:\Users\Subject\djangoshop\myenv\lib\site-packages\django\utils\six.py"
, line 658, in reraise
raise value.with_traceback(tb)
File "C:\Users\Subject\djangoshop\myenv\lib\site-packages\django\utils\autorel
oad.py", line 229, in wrapper
fn(*args, **kwargs)
File "C:\Users\Subject\djangoshop\myenv\lib\site-packages\django\__init__.py",
line 18, in setup
File "C:\Users\Subject\djangoshop\myenv\lib\site-packages\django\apps\registry
.py", line 85, in populate
app_config = AppConfig.create(entry)
File "C:\Users\Subject\djangoshop\myenv\lib\site-packages\django\apps\config.p
y", line 86, in create
module = import_module(entry)
File "C:\Python34\lib\importlib\__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked
ImportError: No module named 'shop'

There is a blank
file in the app shop/.

This picture should show some of the tree. I took it from PyCharm. (I tried the tree command in the command prompt but it was terribly long.)

I think I followed the directory structure given by the book:

django-admin startproject myshop
cd myshop/
django-admin startapp shop

I was not able to create the virtual environment the way the book instructs, so I created it following this tutorial http://tutorial.djangogirls.org/en/django_installation/


Solution: I created the app in the wrong folder. Come to think of it, I think I used this command:

django-admin startproject myshop .

With the dot in the end, as some tutorials recommend. So that messed up the structure so it became incompatible with the book's instructions.

So, as Alasdair recommended, I started the project again from the beginning, and the problem disappeared.