Help: 'django.utils.six.moves' is not a package

751 views
Skip to first unread message

Derek Zeng

unread,
Apr 8, 2018, 8:39:10 PM4/8/18
to Django users
I got the following error when running pytest in django. Help is appreciated.

This is the test I run
import pytest
from .factories import *

@pytest.mark.django_db
def test_with_client(client):
PostFactory.create() # if commented out, the error is gone
response = client.get('/')

body = str(response.content)
assert 'Mysite' in body
PostFactory creates a Post object in the database


apps/blog/tests/test_post.py:5 (test_with_client)
client = <django.test.client.Client object at 0x1040cf3c8>
@pytest.mark.django_db
def test_with_client(client):
p = PostFactory.create()

> response = client.get('/')
blog/tests/test_post.py:10: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../../../.virtualenvs/django/lib/python3.6/site-packages/django/test/client.py:517: in get
response = super().get(path, data=data, secure=secure, **extra)
../../../../.virtualenvs/django/lib/python3.6/site-packages/django/test/client.py:332: in get
return self.generic('GET', path, secure=secure, **r)
../../../../.virtualenvs/django/lib/python3.6/site-packages/django/test/client.py:404: in generic
return self.request(**r)
../../../../.virtualenvs/django/lib/python3.6/site-packages/django/test/client.py:467: in request
response = self.handler(environ)
../../../../.virtualenvs/django/lib/python3.6/site-packages/django/test/client.py:125: in __call__
self.load_middleware()
../../../../.virtualenvs/django/lib/python3.6/site-packages/django/core/handlers/base.py:37: in load_middleware
middleware = import_string(middleware_path)
../../../../.virtualenvs/django/lib/python3.6/site-packages/django/utils/module_loading.py:17: in import_string
module = import_module(module_path)
../../../../.virtualenvs/django/lib/python3.6/importlib/__init__.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:994: in _gcd_import
???
<frozen importlib._bootstrap>:971: in _find_and_load
???
<frozen importlib._bootstrap>:955: in _find_and_load_unlocked
???
<frozen importlib._bootstrap>:665: in _load_unlocked
???
<frozen importlib._bootstrap_external>:678: in exec_module
???
<frozen importlib._bootstrap>:219: in _call_with_frames_removed
???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
from __future__ import absolute_import

import re

from django import http
from django.apps import apps
from django.utils.cache import patch_vary_headers
> from django.utils.six.moves.urllib.parse import urlparse
E ModuleNotFoundError: No module named 'django.utils.six.moves.urllib'; 'django.utils.six.moves' is not a package
../../../../.virtualenvs/django/lib/python3.6/site-packages/corsheaders/middleware.py:8: ModuleNotFoundError


Avraham Serour

unread,
Apr 9, 2018, 3:48:38 PM4/9/18
to django-users
sounds like django 2 removed six and some library you are using still hopes it exists.

what django version are you using?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/23957c7e-9aca-4494-a06a-20cbf0fc857b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Derek Zeng

unread,
Apr 9, 2018, 9:47:45 PM4/9/18
to django...@googlegroups.com
I'm using django 2.0. 
What exactly is the purpose of django.utils.six.moves module? 
I have read the source but don't quite understand. Seems like a poly-fill of pre-existing libraries like urllib


--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/EmfIjFICjyU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Babatunde Akinyanmi

unread,
Apr 10, 2018, 1:39:05 AM4/10/18
to Django users


On Tue, 10 Apr 2018, 02:47 Derek Zeng, <zen...@gmail.com> wrote:
I'm using django 2.0. 
What exactly is the purpose of django.utils.six.moves module? 
Allowing a code base to be able to run on both python 2 and python 3

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/EmfIjFICjyU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Derek Zeng

unread,
Apr 10, 2018, 1:32:33 PM4/10/18
to django...@googlegroups.com


On Tue, Apr 10, 2018, 1:39 AM Babatunde Akinyanmi <tunde...@gmail.com> wrote:


On Tue, 10 Apr 2018, 02:47 Derek Zeng, <zen...@gmail.com> wrote:
I'm using django 2.0. 
What exactly is the purpose of django.utils.six.moves module? 
Allowing a code base to be able to run on both python 2 and python 3

yeah, but what role does moves module play here? if an old module is not found here, where does it look for it?

Julio Biason

unread,
Apr 10, 2018, 1:58:07 PM4/10/18
to django...@googlegroups.com
Six is self-contained it does look anywhere, it has its own list of “how it was before and how it is now”.

In the case of moves, it has conditions of “module urlparse is urlparse in python 2 and urllib.parse in python 3” and then sets its own move module to point to one of those, based on python version.

It’s weird that it can find six, but not the “moves” module. Have you tried deleting your virtual end and creating it again, with the new versions?


From: django...@googlegroups.com <django...@googlegroups.com> on behalf of Derek Zeng <zen...@gmail.com>
Sent: Tuesday, April 10, 2018 10:31:27 AM
To: django...@googlegroups.com
Subject: Re: Help: 'django.utils.six.moves' is not a package
 

Babatunde Akinyanmi

unread,
Apr 11, 2018, 1:39:36 AM4/11/18
to Django users
Do you have any module making use of six? Also is there any change in the story if you do `python3 manage.py [command]`
Reply all
Reply to author
Forward
0 new messages