ModuleNotFoundError: No module named 'collection'


#1

Hi!

So I am stuck on the very initial stage of setting up the project… :(

I have reviewed the code you posted on GitHub, but it didn’t help me much.

When I am trying to migrate, console prints:

Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/home/aleksanderj/webprojects/myhellowebapp/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/home/aleksanderj/webprojects/myhellowebapp/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
    django.setup()
  File "/home/aleksanderj/webprojects/myhellowebapp/venv/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/aleksanderj/webprojects/myhellowebapp/venv/lib/python3.6/site-packages/django/apps/registry.py", line 89, in populate
    app_config = AppConfig.create(entry)
  File "/home/aleksanderj/webprojects/myhellowebapp/venv/lib/python3.6/site-packages/django/apps/config.py", line 90, in create
    module = import_module(entry)
  File "/usr/lib/python3.6/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 'collection'

This sucks so much!


#2

Did you run the startapp command to create the app “collection”?

Does your directory look like this? https://github.com/hellowebbooks/hellowebapp-code (where the “collection” folder/directory is in the same place as manage.py)?

Basically Django doesn’t think you have an app named “collection” so I’m trying to figure out where it could be on your end. :)


#3

Okay so I have deleted all the files to configure everything again, and I perhaps should mention that your way of creating a venv does not work, this one does:
~/projects/myhellowebapp$ python3 -m venv venv

I hope that’s okay.


#4

The ‘projects’ folder looks like this:

Okay so I have literally no clue what’s wrong… There is no manage.py in the projects folder, but there shouldn’t be, right? Not before I run the migrate command


#5

Double-checked - yes I started the app ‘collection’
Screenshot_20181108_214509


#6

so I tried doing the same on my other computer, and got a different error

~/projects/myhellowebapp$ python manage.py migrate
Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    "Couldn't import Django. Are you sure it's installed and "
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
(venv) aleksanderjess@ubuntu-ux360cak:~/projects/myhellowebapp$ 

I am so so lost…


#7

So looks like your collection folder is in the wrong place and you’re not in your virtualenvironment bubble. :)

So, first, delete the collection folder that’s in your projects folder. Then, go “into” your myhellowebapp folder (inspect the contents, make sure that there is a manage.py there).

Start your virtual environment (https://hellowebbooks.com/setup/#start-virtualenv — see the command to activate the environment). Think of your virtual environment like a bubble where things are. If your virtual environment isn’t activated, you’re not in the bubble, and you can’t access things “in” the bubble (like Django), which is why it says it can’t access Django in your other error message.

Once your environment is activated (and you get a (venv) or something similar in your command line), then create your collection app. https://hellowebbooks.com/setup/#create-app

Looks like before you created the app in your “projects” folder, not in your “myhellowebapp” folder. This’ll put it in the right place.

Once the app is created and in the right place, then you can run migrate.

If you know you’ve activated your environment but your computer complains it doesn’t has Django, try installing Django again (https://hellowebbooks.com/setup/#install-django). You might have installed it “outside” the bubble, but once you’re within the bubble, you might have to install it again.

Let me know if you receive any other errors. :)


#8

Okay so, this was a silly mistake.

Everything works now. Thanks a lot!