Django database migration error - python

I have a Django project connected to Gmail API.
When I try to do database migration it returns this:
C:\Users\Peter\Desktop\FastProject>python manage.py migrate FastProject
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", l
ine 371, in execute_from_command_line
utility.execute()
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", l
ine 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line
288, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line
332, in execute
self.check()
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line
364, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\commands\migrat
e.py", line 58, in _run_checks
issues.extend(super()._run_checks(**kwargs))
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line
351, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\checks\registry.py", line
73, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\checks\urls.py", line 13,
in check_url_config
return check_resolver(resolver)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\checks\urls.py", line 23,
in check_resolver
return check_method()
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\resolvers.py", line 397, i
n check
for pattern in self.url_patterns:
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\functional.py", line 36,
in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\resolvers.py", line 536, i
n url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\functional.py", line 36,
in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\resolvers.py", line 529, i
n urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\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 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\Peter\Desktop\FastProject\FastProject\urls.py", line 21, in <module>
path('', include('mainApp.urls')),
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\conf.py", line 34, in incl
ude
urlconf_module = import_module(urlconf_module)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\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 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\Peter\Desktop\FastProject\mainApp\urls.py", line 3, in <module>
from . import views
File "C:\Users\Peter\Desktop\FastProject\mainApp\views.py", line 2, in <module>
from quickstart import go
ModuleNotFoundError: No module named 'quickstart'
I have also tried 'makemigrations' and old one 'syncdb', but first one gives the same error and the second one isn't used anymore.I use SQLite3. This is in my settings :
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'results_db.sqlite3'),
}
}
"quickstart" is a file from which I call a function. I guess all the names are correct, so I don't know what's the problem. This is error was before but I decided to think about it later.
Thanks.

It's definitely related to this line:
File "C:\Users\Peter\Desktop\FastProject\mainApp\views.py", line 2, in <module>
from quickstart import go
ModuleNotFoundError: No module named 'quickstart'
Looks like you're missing the quickstart module. Is it related to some tutorial? Maybe you forgot to activate your virtual environment?
Update:
You should use local imports or provide the full path to the package if you have such a project structure https://ibb.co/fdvaRJ:
from .quickstart import go
or
from mainApp.quickstart import go
Or you could put your quickstart.py module one level upper and just use
from quickstart import go
as you do now.
Don't forget to check out the official guide on packaging and modules in Python: https://docs.python.org/3/tutorial/modules.html#packages

I did some manipulations with that quickstart file. First I created in every folder 'init.py', then I created an empty folder in app directory and dragndropped there 'quickstart.py' and created there an empty "init" file too. Didn't work: the error just changed from ModuleNotFoundError: No module named 'quickstart' to ModuleNotFoundError: No module named 'api.quickstart'.
Then I deleted all "init" files created 2 minutes ago, put 'quickstart' file back to the root folder of my app and also drag'n'dropped an "init" file.
The error became just like " from quickstart import go
ImportError: cannot import name 'go' ". What I did next is just changed "from quickstart import go" to "import quickstart" and then called go function like "quickstart.go()"
Too much text so images for better understanding:
https://ibb.co/fdvaRJ
https://ibb.co/kzgPmJ
https://ibb.co/jyjVty

Related

Why does command prompt throws" Syntax Error: Generator expression must be parenthesized " while creating a Django App named Authentication?

I am new to Django and was trying to make a Django project inside the virtualenv to learn but getting following error on python manage.py startapp Authentication:
python manage.py startapp Authentication
Traceback (most recent call last):
File "C:\Users\Prompt\Desktop\Django\manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "D:\anaconda\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line
utility.execute()
File "D:\anaconda\lib\site-packages\django\core\management\__init__.py", line 337, in execute
django.setup()
File "D:\anaconda\lib\site-packages\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "D:\anaconda\lib\site-packages\django\apps\registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "D:\anaconda\lib\site-packages\django\apps\config.py", line 94, in create
module = import_module(entry)
File "D:\anaconda\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "D:\anaconda\lib\site-packages\django\contrib\admin\__init__.py", line 4, in <module>
from django.contrib.admin.filters import (
File "D:\anaconda\lib\site-packages\django\contrib\admin\filters.py", line 10, in <module>
from django.contrib.admin.options import IncorrectLookupParameters
File "D:\anaconda\lib\site-packages\django\contrib\admin\options.py", line 12, in <module>
from django.contrib.admin import helpers, widgets
File "D:\anaconda\lib\site-packages\django\contrib\admin\widgets.py", line 151
'%s=%s' % (k, v) for k, v in params.items(),
^
SyntaxError: Generator expression must be parenthesized

Django-error OSError: dlopen() failed to load a library: cairo / cairo-2 / cairo-gobject-2

When I do manage.py makemigrations
An error like this occurs
PS C:\Users\User\PycharmProject\onlineshop-master> python .\manage.py makemigrations
Traceback (most recent call last):
File "C:\Users\User\PycharmProject\onlineshop-master\manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\User\PycharmProject\onlineshop\venv\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\User\PycharmProject\onlineshop\venv\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\User\PycharmProject\onlineshop\venv\lib\site-packages\django\core\management\base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\User\PycharmProject\onlineshop\venv\lib\site-packages\django\core\management\base.py", line 350, in execute
self.check()
File "C:\Users\User\PycharmProject\onlineshop\venv\lib\site-packages\django\core\management\base.py", line 376, in check
all_issues = self._run_checks(
File "C:\Users\User\PycharmProject\onlineshop\venv\lib\site-packages\django\core\management\base.py", line 366, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\User\PycharmProject\onlineshop\venv\lib\site-packages\django\core\checks\registry.py", line 71, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\User\PycharmProject\onlineshop\venv\lib\site-packages\django\core\checks\urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "C:\Users\User\PycharmProject\onlineshop\venv\lib\site-packages\django\core\checks\urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
File "C:\Users\User\PycharmProject\onlineshop\venv\lib\site-packages\django\utils\functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\User\PycharmProject\onlineshop\venv\lib\site-packages\django\urls\resolvers.py", line 533, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\User\PycharmProject\onlineshop\venv\lib\site-packages\django\utils\functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\User\PycharmProject\onlineshop\venv\lib\site-packages\django\urls\resolvers.py", line 526, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\User\PycharmProject\onlineshop-master\config\urls.py", line 24, in <module>
path('order/', include('order.urls')),
File "C:\Users\User\PycharmProject\onlineshop\venv\lib\site-packages\django\urls\conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\User\PycharmProject\onlineshop-master\order\urls.py", line 2, in <module>
from .views import *
File "C:\Users\User\PycharmProject\onlineshop-master\order\views.py", line 36, in <module>
import weasyprint
File "C:\Users\User\PycharmProject\onlineshop\venv\lib\site-packages\weasyprint\__init__.py", line 393, in <module>
from .css import preprocess_stylesheet # noqa
File "C:\Users\User\PycharmProject\onlineshop\venv\lib\site-packages\weasyprint\css\__init__.py", line 25, in <module>
from . import computed_values
File "C:\Users\User\PycharmProject\onlineshop\venv\lib\site-packages\weasyprint\css\computed_values.py", line 17, in <module>
from .. import text
File "C:\Users\User\PycharmProject\onlineshop\venv\lib\site-packages\weasyprint\text.py", line 14, in <module>
import cairocffi as cairo
File "C:\Users\User\PycharmProject\onlineshop\venv\lib\site-packages\cairocffi\__init__.py", line 41, in <module>
cairo = dlopen(ffi, 'cairo', 'cairo-2', 'cairo-gobject-2')
File "C:\Users\User\PycharmProject\onlineshop\venv\lib\site-packages\cairocffi\__init__.py", line 38, in dlopen
raise OSError("dlopen() failed to load a library: %s" % ' / '.join(names))
OSError: dlopen() failed to load a library: cairo / cairo-2 / cairo-gobject-2
I can't figure out a workaround.
How can I solve this?
'''
pip install cffi
'''
Requirement already satisfied: cffi in c:\users\user\pycharmproject\onlineshop\venv\lib\site-packages (1.15.0)
Requirement already satisfied: pycparser in c:\users\user\pycharmproject\onlineshop\venv\lib\site-packages (from cffi) (2.19)
check the cairocffi package has an issue or not and even it is correctly installed or not. And try to install it again, so maybe these issues will be solved.
Also check your database. like when you write python manage.py make migrations , if your database is not created as superuser, so it will give you errors
if your packages are already satisfied then try to uninstall it

coverage using wrong python path, although venv is sourced

I am working on a Django project and trying to run the command coverage run --source='.' manage.py test myapp from the Django documentation. Somehow coverage uses a different python path than the virtual environment I am in (I guess that is the reason that the module is not found)
I get the following output:
(venv) username in ~/project on branch basket > coverage run --source='.' manage.py test myapp
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/Users/username/.pyenv/versions/3.7.2/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/Users/username/.pyenv/versions/3.7.2/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/username/.pyenv/versions/3.7.2/lib/python3.7/site-packages/django/core/management/commands/test.py", line 23, in run_from_argv
super().run_from_argv(argv)
File "/Users/username/.pyenv/versions/3.7.2/lib/python3.7/site-packages/django/core/management/base.py", line 322, in run_from_argv
parser = self.create_parser(argv[0], argv[1])
File "/Users/username/.pyenv/versions/3.7.2/lib/python3.7/site-packages/django/core/management/base.py", line 296, in create_parser
self.add_arguments(parser)
File "/Users/username/.pyenv/versions/3.7.2/lib/python3.7/site-packages/django/core/management/commands/test.py", line 44, in add_arguments
test_runner_class = get_runner(settings, self.test_runner)
File "/Users/username/.pyenv/versions/3.7.2/lib/python3.7/site-packages/django/test/utils.py", line 302, in get_runner
test_runner_class = test_runner_class or settings.TEST_RUNNER
File "/Users/username/.pyenv/versions/3.7.2/lib/python3.7/site-packages/django/conf/__init__.py", line 83, in __getattr__
self._setup(name)
File "/Users/username/.pyenv/versions/3.7.2/lib/python3.7/site-packages/django/conf/__init__.py", line 70, in _setup
self._wrapped = Settings(settings_module)
File "/Users/username/.pyenv/versions/3.7.2/lib/python3.7/site-packages/django/conf/__init__.py", line 177, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/Users/username/.pyenv/versions/3.7.2/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/username/project/config/settings.py", line 14, in <module>
from decouple import config, Csv
ModuleNotFoundError: No module named 'decouple'
I am using venv from the regular python installation and checked my venv by importing a non-existent module in my settings.py:
from testmodule import test, which gives me the following output for the command python manage.py runserver
(venv) username in ~/project > python manage.py runserver
Traceback (most recent call last):
File "/Users/username/project/venv/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 61, in execute
super().execute(*args, **options)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 68, in handle
if not settings.DEBUG and not settings.ALLOWED_HOSTS:
File "/Users/username/project/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 82, in __getattr__
self._setup(name)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 69, in _setup
self._wrapped = Settings(settings_module)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 170, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/Users/username/project/config/settings.py", line 16, in <module>
from testmodule import test
ModuleNotFoundError: No module named 'testmodule'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/username/project/manage.py", line 22, in <module>
main()
File "/Users/username/project/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/Users/username/project/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/core/management/base.py", line 367, in run_from_argv
connections.close_all()
File "/Users/username/project/venv/lib/python3.9/site-packages/django/db/utils.py", line 208, in close_all
for alias in self:
File "/Users/username/project/venv/lib/python3.9/site-packages/django/utils/connection.py", line 73, in __iter__
return iter(self.settings)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/utils/connection.py", line 45, in settings
self._settings = self.configure_settings(self._settings)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/db/utils.py", line 144, in configure_settings
databases = super().configure_settings(databases)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/utils/connection.py", line 50, in configure_settings
settings = getattr(django_settings, self.settings_name)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 82, in __getattr__
self._setup(name)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 69, in _setup
self._wrapped = Settings(settings_module)
File "/Users/username/project/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 170, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/Users/username/project/config/settings.py", line 16, in <module>
from testmodule import test
ModuleNotFoundError: No module named 'testmodule'
To me the problem doesn't seem related to django or the python-decouple module, but coverage not using the python path of my sourced venv. I tried to search the docs from coverage but couldn't identify what function or method is used when running coverage run can somebody help me out on where to look or how to identify the problem?
This seems to be a conflict with your global python packages.
As your log suggests, coverage is from /Users/username/.pyenv/versions/3.7.2/.
And you want to use the /Users/username/project/venv/lib/python3.9/.
There are 2 ways to do this, uninstall global coverage.
(venv) $ deactivate
$ pip3 uninstall coverage
$ source venv/bin/activate
(venv) $ python -m pip install coverage
Or if you plan on keeping global package you can try this.
(venv) $ python -m pip install coverage
(venv) $ python -m coverage
This will get the packages with respect to /Users/username/project/venv/lib/python3.9/

Why does my Django Project not recognize apps installed on the settings?

I am trying to build my portfolio in Django and encountered an error after installing my app. It seems like it doesn't recognize the app on my INSTALLED_APPS. I've tried using 'blog' and 'blog.apps.BlogConfig' but nothing seems to be recognized.
I run the runserver with python manage.py runserver and python manage.py runserver but both returns ModuleNotFoundError: No module named 'blog.urls'
This is the whole traceback
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/core/management/base.py", line 390, in check
include_deployment_checks=include_deployment_checks,
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/core/management/base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/core/checks/registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/urls/resolvers.py", line 398, in check
for pattern in self.url_patterns:
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/urls/resolvers.py", line 579, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/urls/resolvers.py", line 572, in urlconf_module
return import_module(self.urlconf_name)
File "/Users/usr/django-portfolio/env/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/usr/django-portfolio/portfolio/portfolio/urls.py", line 21, in <module>
path('', include('blog.urls'))
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/Users/usr/django-portfolio/env/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'blog.urls'
My INSTALLED_APPS is
INSTALLED_APPS = [
....
'blog'
]
URL in Settings
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('blog.urls'))
]
No module named 'blog.urls' means you don't have urls module inside blog.
You need to create a file named urls.py inside the blog app.
And you need to define some routes there.
After that below line
path('', include('blog.urls'))
will work fine.
Make sure you have structured your blog app and parent app properly. And you module path is set properly. For reference you can also see
Django Installed Apps Location

"moduleNotFoundError" when sets scrapy as an app in django

When I tried to start my scrapy demo with scrapy crawl getCommodityInfo, the error below occurred.
C:\Users\柘宇\PycharmProjects\GraduationProject\spiders\bin\JDSpider>scrapy crawl getCommodityInfo
Traceback (most recent call last):
File "D:\Anacaonda\Scripts\scrapy-script.py", line 5, in <module>
sys.exit(scrapy.cmdline.execute())
File "D:\Anacaonda\lib\site-packages\scrapy\cmdline.py", line 141, in execute
cmd.crawler_process = CrawlerProcess(settings)
File "D:\Anacaonda\lib\site-packages\scrapy\crawler.py", line 238, in __init__
super(CrawlerProcess, self).__init__(settings)
File "D:\Anacaonda\lib\site-packages\scrapy\crawler.py", line 129, in __init__
self.spider_loader = _get_spider_loader(settings)
File "D:\Anacaonda\lib\site-packages\scrapy\crawler.py", line 325, in _get_spider_loader
return loader_cls.from_settings(settings.frozencopy())
File "D:\Anacaonda\lib\site-packages\scrapy\spiderloader.py", line 45, in from_settings
return cls(settings)
File "D:\Anacaonda\lib\site-packages\scrapy\spiderloader.py", line 23, in __init__
self._load_all_spiders()
File "D:\Anacaonda\lib\site-packages\scrapy\spiderloader.py", line 32, in _load_all_spiders
for module in walk_modules(name):
File "D:\Anacaonda\lib\site-packages\scrapy\utils\misc.py", line 71, in walk_modules
submod = import_module(fullpath)
File "D:\Anacaonda\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "C:\Users\柘宇\PycharmProjects\GraduationProject\spiders\bin\JDSpider\JDSpider\spiders\getCommodityInfo.py", line 12, in <module>
from spiders.bin.JDSpider.JDSpider.items import JDCommodity
ModuleNotFoundError: No module named 'spiders'
It seems that the spider cannot be found, but I don't know why it happened. My whole project hierarchy is here. GraduationProject is the django project. main and spiders are the applications of django. The bin directory stores two demo scrapy projects. When I entered the JDSpider trying to run it, the error occurred. Could you help me fix it?
PS. My spider name: name = "getCommodityInfo"
With the solution applied by PS1212, the scrapy demo could run. However the pycharm warns like this. What happened?
Because it it not recognizing you project module.
Try this:
from JDSpider.items import JDCommodity

Categories