1

Aim: Build projectoxford into raspberrypi3 - https://channel9.msdn.com/Blogs/jsturtevant/Setting-up-Project-Oxford-for-Python-on-Windows

I have reached the steps of:

pi@raspberrypi:~/happy-image-tester-django $ source env/bin/activate
(env) pi@raspberrypi:~/happy-image-tester-django $ python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 16, in <module>
    from django.core.management import execute_from_command_line
ImportError: No module named 'django'

After which, I tried to download django module by using

pip install django

However, after downloading django, when I try to run python manage.py runserver, I have unhandled exception. The results are as shown below.

(env) pi@raspberrypi:~/happy-image-tester-django $ python manage.py runserverPerforming system checks...

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x75b7ac00>
Traceback (most recent call last):
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/utils/autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 121, in inner_run
    self.check(display_num_errors=True)
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/core/management/base.py", line 364, in check
    include_deployment_checks=include_deployment_checks,
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/core/management/base.py", line 351, in _run_checks
    return checks.run_checks(**kwargs)
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/core/checks/registry.py", line 73, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/core/checks/urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/core/checks/urls.py", line 23, in check_resolver
    return check_method()
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/urls/resolvers.py", line 397, in check
    for pattern in self.url_patterns:
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/utils/functional.py", line 36, in get
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/urls/resolvers.py", line 536, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/utils/functional.py", line 36, in get
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/urls/resolvers.py", line 529, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 673, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/pi/happy-image-tester-django/HappyOrMad/urls.py", line 6, in <module>
    from django.conf.urls import patterns, url
ImportError: cannot import name 'patterns'

A check online (https://github.com/jgiannuzzi/taiga-contrib-saml-auth/issues/1) told me that url.py is now fix but I have no idea why it doesnt work still. Other online checks shows that patterns have been deprecated after Django version 1.10; I tried to debug according to the results found online but all could not work for me. I have listed out some of the codes I've tried below.

https://stackoverflow.com/questions/38786036/importerror-cannot-import-name-patterns states that I can use from django.conf.urls import include, url instead of django.conf.urls import patterns, url ; but after editing accordingly, my error results are as follows:

(env) pi@raspberrypi:~/happy-image-tester-django $ python manage.py runserver
Performing system checks...

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x75ba7c00>
Traceback (most recent call last):
 File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/utils/autoreload.py", line 225, in wrapper
   fn(*args, **kwargs)
 File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 121, in inner_run
   self.check(display_num_errors=True)
 File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/core/management/base.py", line 364, in check
   include_deployment_checks=include_deployment_checks,
 File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/core/management/base.py", line 351, in _run_checks
   return checks.run_checks(**kwargs)
 File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/core/checks/registry.py", line 73, in run_checks
   new_errors = check(app_configs=app_configs)
 File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/core/checks/urls.py", line 13, in check_url_config
   return check_resolver(resolver)
 File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/core/checks/urls.py", line 23, in check_resolver
   return check_method()
 File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/urls/resolvers.py", line 397, in check
   for pattern in self.url_patterns:
 File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/utils/functional.py", line 36, in __get__
   res = instance.__dict__[self.name] = self.func(instance)
 File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/urls/resolvers.py", line 536, in url_patterns
   patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
 File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/utils/functional.py", line 36, in __get__
   res = instance.__dict__[self.name] = self.func(instance)
 File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/urls/resolvers.py", line 529, in urlconf_module
   return import_module(self.urlconf_name)
 File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
   return _bootstrap._gcd_import(name[level:], package, level)
 File "<frozen importlib._bootstrap>", line 986, in _gcd_import
 File "<frozen importlib._bootstrap>", line 969, in _find_and_load
 File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
 File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
 File "<frozen importlib._bootstrap_external>", line 669, in exec_module
 File "<frozen importlib._bootstrap_external>", line 775, in get_code
 File "<frozen importlib._bootstrap_external>", line 735, in source_to_code
 File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
 File "/home/pi/happy-image-tester-django/HappyOrMad/urls.py", line 9
   from django.conf.urls import include

I have also tried changing the url.py as follows by uncommenting the

"from django.conf.urls import include
from django.contrib import admin
admin.autodiscover()"


"""
Definition of urls for HappyOrMad.
"""

from datetime import datetime
from django.conf.urls import pattern, url

# Uncomment the next lines to enable the admin:
from django.conf.urls import include
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
   # Examples:
   url(r'^$', 'app.views.home', name='home'),
   url(r'^upload','app.views.upload', name='upload'),

   # Uncomment the admin/doc line below to enable admin documentation:
   # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

   # Uncomment the next line to enable the admin:
   # url(r'^admin/', include(admin.site.urls)),
)

The original url.py file is as follows:

"""
Definition of urls for HappyOrMad.
"""

from datetime import datetime
from django.conf.urls import patterns, url

# Uncomment the next lines to enable the admin:
# from django.conf.urls import include
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    url(r'^$', 'app.views.home', name='home'),
    url(r'^upload','app.views.upload', name='upload'),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    # url(r'^admin/', include(admin.site.urls)),
)

After editing the url.py with the code provided, the error is as follows:

(env) pi@raspberrypi:~/happy-image-tester-django $ python manage.py runserver
Performing system checks...

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x75bfbc00>
Traceback (most recent call last):
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/utils/autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 121, in inner_run
    self.check(display_num_errors=True)
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/core/management/base.py", line 364, in check
    include_deployment_checks=include_deployment_checks,
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/core/management/base.py", line 351, in _run_checks
    return checks.run_checks(**kwargs)
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/core/checks/registry.py", line 73, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/core/checks/urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/core/checks/urls.py", line 23, in check_resolver
    return check_method()
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/urls/resolvers.py", line 397, in check
    for pattern in self.url_patterns:
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/utils/functional.py", line 36, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/urls/resolvers.py", line 536, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/utils/functional.py", line 36, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/urls/resolvers.py", line 529, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 673, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/pi/happy-image-tester-django/HappyOrMad/urls.py", line 11, in <module>
    url(r'^$', 'app.views.home', name='home'),
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/conf/urls/__init__.py", line 13, in url
    return re_path(regex, view, kwargs, name)
  File "/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/urls/conf.py", line 73, in _path
    raise TypeError('view must be a callable or a list/tuple in the case of include().')
TypeError: view must be a callable or a list/tuple in the case of include().

Migration error and remove django warning:

(env) pi@raspberrypi:~/happy-image-tester-django $ python manage.py runserverPerforming system checks...

/home/pi/happy-image-tester-django/HappyOrMad/urls.py:13: RemovedInDjango110Warning: Support for string view arguments to url() is deprecated and will be removed in Django 1.10 (got app.views.home). Pass the callable instead.
  url(r'^$', 'app.views.home', name='home'),

/home/pi/happy-image-tester-django/HappyOrMad/urls.py:14: RemovedInDjango110Warning: Support for string view arguments to url() is deprecated and will be removed in Django 1.10 (got app.views.upload). Pass the callable instead.
  url(r'^upload','app.views.upload', name='upload'),

System check identified no issues (0 silenced).

You have unapplied migrations; your app may not work properly until they are applied.
Run 'python manage.py migrate' to apply them.

January 17, 2018 - 10:51:12
Django version 1.9.1, using settings 'HappyOrMad.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
python./home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/template/utils.py:37: RemovedInDjango110Warning: You haven't defined a TEMPLATES setting. You must do so before upgrading to Django 1.10. Otherwise Django will be unable to load templates.
  "unable to load templates.", RemovedInDjango110Warning)

/home/pi/happy-image-tester-django/env/lib/python3.5/site-packages/django/shortcuts.py:89: RemovedInDjango110Warning: The context_instance argument of render_to_string is deprecated.
  using=using)
1

One of the questions you linked actually does point to the answer: in Django 1.8, the patterns function became obsolete, and was replaced with a normal Python list.

The correct urls.py would be as follows:

from datetime import datetime
from django.conf.urls import url
from app.views import home, upload

# Uncomment the next lines to enable the admin:
# from django.conf.urls import include
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = [
    # Examples:
    url(r'^$', home, name='home'),
    url(r'^upload', upload, name='upload'),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    # url(r'^admin/', include(admin.site.urls)),
]

Note that the import to patterns has been removed, and patterns('', ...) has been replaced by a list, which is denoted by [ ... ].


Django 1.8 wasn't released until April 2016, whereas the video you're following is from February 2016. If you didn't want to perform any code changes, you could instead just install an outdated version of Django:

pip install django==1.7.11

I'd recommend the method above of fixing the code, though, as the more recent versions of Django come with more security patches and bug fixes.

  • Thank you for your reply! I have tried changing the url.py file as accordance of the code you gave, but I have the error as edited in my post ;(( – GoodCodes Jan 17 '18 at 16:19
  • 1
    @GoodCodes Looks like another issue related to using a relatively new version of Django. I've edited with the fix, or alternatively you can try the old code and install an older version of Django instead. I suspect you might bump into more issues with using a 'too new' version of Django, so it might be worth just using the old version of Django if this fix doesn't work. – Aurora0001 Jan 17 '18 at 16:25
  • Thank you so much!!! It works now, or so I believe? :') The errors they gave me now is that of migration error as shown in the post above and the remove django warning: You have unapplied migrations; your app may not work properly until they are applied. Run 'python manage.py migrate' to apply them. Would these matter later as I am looking to modify this application? @Aurora0001 – GoodCodes Jan 17 '18 at 17:01
  • You do need to run the migrations (these set up the database used by the web app you want to run, so not running it will probably cause it to fail later on). As the warning suggests, just run python manage.py migrate to solve that and you should be good to go after that. – Aurora0001 Jan 17 '18 at 17:03
  • Ohh icic, hmm, but nothing happens after python manage.py migrate right? Because nothing happen after I typed that, it just goes to a blank next line. By the way, from the website given on the first sentence of this post, at about 4:27, the author opens the activate.bat file by using code env; here's the link for this question: raspberrypi.stackexchange.com/questions/77899/… I would appreciate your help greatly if you could take a look at it please! Thank you x1000000! @ Aurora0001 – GoodCodes Jan 17 '18 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.