ImportError: cannot import name wraps #298

grantmcconnaughey opened this Issue Jul 28, 2015 · 10 comments


None yet

5 participants


I am getting an ImportError any time I run tests where I use mock. I'm using mock 1.3.0.

The error is ImportError: cannot import name wraps. It doesn't seem that installing mock requires six in when it probably should. And if it requires a specific version of six (one that has a function called wraps) then it should specify that as well.

Looks like I'm not the only one with this issue:


ImportError: Failed to import test module: my_app.tests.test_forms
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/", line 254, in _find_tests
    module = self._get_module_from_name(name)
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/", line 232, in _get_module_from_name
  File "/Users/grant/my_app/tests/", line 2, in <module>
    from mock import patch, MagicMock
  File "/Users/grant/.virtualenvs/sidekick/lib/python2.7/site-packages/mock/", line 2, in <module>
    import mock.mock as _mock
  File "/Users/grant/.virtualenvs/sidekick/lib/python2.7/site-packages/mock/", line 68, in <module>
    from six import wraps
ImportError: cannot import name wraps

We have a versioned dependency on six 1.7 or newer. What version of six do you have installed?


I think we're using 1.5.

Your dependency is in requirements.txt, not in, therefore six is not installed when mock is installed. needs changed to this:

kylios commented Jul 28, 2015

I am also getting this error using mock 1.3.0 and six 1.9.0:

$ sudo pip install mock
Collecting mock
  Downloading mock-1.3.0-py2.py3-none-any.whl (56kB)
    100% |████████████████████████████████| 57kB 431kB/s 
Collecting funcsigs (from mock)
  Downloading funcsigs-0.4-py2.py3-none-any.whl
Collecting pbr>=0.11 (from mock)
  Downloading pbr-1.3.0-py2.py3-none-any.whl (83kB)
    100% |████████████████████████████████| 86kB 453kB/s 
Collecting six>=1.7 (from mock)
  Downloading six-1.9.0-py2.py3-none-any.whl
Installing collected packages: funcsigs, pbr, six, mock
Successfully installed funcsigs-0.4 mock-1.3.0 pbr-1.3.0 six-1.9.0

My error:

$ python tests/
Traceback (most recent call last):
  File "tests/", line 8, in <module>
    from mock import patch
  File "/Library/Python/2.7/site-packages/mock/", line 2, in <module>
    import mock.mock as _mock
  File "/Library/Python/2.7/site-packages/mock/", line 68, in <module>
    from six import wraps
ImportError: cannot import name wraps

@grantmcconnaughey - pbr reflects requirements.txt into metadata, no change to should be needed if thats working correctly. The log from @kylios shows that it does indeed work:
Collecting six>=1.7 (from mock)
Downloading six-1.9.0-py2.py3-none-any.whl

If you could include the transcript of your pip install showing it not work, plus a 'pip list' showing the versions of pip and setuptools, we might be able to figure out why it didn't work for you.


@kylios thats very weird: I just checked that I can do 'from mock import patch' in a clean venv: just doing:

mkvirtualenv test
pip install -U pip
pip install mock
python -c 'from mock import patch'

worked quite happily.

Can you check that you don't e.g. have a 'six' egg in your current directory or something?
perhaps print six.path from the top of tests/ ?


perhaps print six.path

Ugh, that was the problem for me. I had six installed twice in:

and in

After I removed the six from /usr/lib/ it worked fine:
rm /usr/lib/python2.7/dist-packages/*six*


Ok, so we need @grantmcconnaughey to do the same checks, but so far I'm not seeing an actual mock / mock packaging bug here.


We had six pinned to version 1.5.2. I can't remember...does PIP not install a higher version if we have it set to a specific version in our requirements.txt file? If not then that was the issue and this can be disregarded.


Yes, in all current releases of pip, setting a version on something in a requirements file will then ignore all dependencies that have different versions.

In future, when pip has a resolver (I have a branch that does this), such setups will error instead.

@rbtcollins rbtcollins closed this Jul 29, 2015

@vitalybe I have the same issue with the two paths...

@theY4Kman theY4Kman added a commit to jasonkeene/python-ubersmith that referenced this issue Aug 28, 2015
@theY4Kman theY4Kman fix(reqs): upgrade six>=1.7 to fix mock in tests 2df51ae
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment