New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name wraps #298

Closed
grantmcconnaughey opened this Issue Jul 28, 2015 · 10 comments

Comments

Projects
None yet
5 participants
@grantmcconnaughey

grantmcconnaughey commented Jul 28, 2015

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 setup.py 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: http://stackoverflow.com/questions/31417964/importerror-cannot-import-name-wraps

Traceback:

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/loader.py", 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/loader.py", line 232, in _get_module_from_name
    __import__(name)
  File "/Users/grant/my_app/tests/test_forms.py", line 2, in <module>
    from mock import patch, MagicMock
  File "/Users/grant/.virtualenvs/sidekick/lib/python2.7/site-packages/mock/__init__.py", line 2, in <module>
    import mock.mock as _mock
  File "/Users/grant/.virtualenvs/sidekick/lib/python2.7/site-packages/mock/mock.py", line 68, in <module>
    from six import wraps
ImportError: cannot import name wraps
@rbtcollins

This comment has been minimized.

Show comment
Hide comment
@rbtcollins

rbtcollins Jul 28, 2015

Member

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

Member

rbtcollins commented Jul 28, 2015

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

@grantmcconnaughey

This comment has been minimized.

Show comment
Hide comment
@grantmcconnaughey

grantmcconnaughey Jul 28, 2015

I think we're using 1.5.

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

setuptools.setup(
    install_requires=['six>=1.7'],
    setup_requires=['pbr>=1.3'],
    pbr=True)

grantmcconnaughey commented Jul 28, 2015

I think we're using 1.5.

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

setuptools.setup(
    install_requires=['six>=1.7'],
    setup_requires=['pbr>=1.3'],
    pbr=True)
@kylios

This comment has been minimized.

Show comment
Hide comment
@kylios

kylios Jul 28, 2015

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

$ sudo pip install mock
Password:
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/test_cli.py
Traceback (most recent call last):
  File "tests/test_cli.py", line 8, in <module>
    from mock import patch
  File "/Library/Python/2.7/site-packages/mock/__init__.py", line 2, in <module>
    import mock.mock as _mock
  File "/Library/Python/2.7/site-packages/mock/mock.py", line 68, in <module>
    from six import wraps
ImportError: cannot import name wraps

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
Password:
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/test_cli.py
Traceback (most recent call last):
  File "tests/test_cli.py", line 8, in <module>
    from mock import patch
  File "/Library/Python/2.7/site-packages/mock/__init__.py", line 2, in <module>
    import mock.mock as _mock
  File "/Library/Python/2.7/site-packages/mock/mock.py", line 68, in <module>
    from six import wraps
ImportError: cannot import name wraps
@rbtcollins

This comment has been minimized.

Show comment
Hide comment
@rbtcollins

rbtcollins Jul 28, 2015

Member

@grantmcconnaughey - pbr reflects requirements.txt into setup.py metadata, no change to setup.py 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.

Member

rbtcollins commented Jul 28, 2015

@grantmcconnaughey - pbr reflects requirements.txt into setup.py metadata, no change to setup.py 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.

@rbtcollins

This comment has been minimized.

Show comment
Hide comment
@rbtcollins

rbtcollins Jul 28, 2015

Member

@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/test_cli.py ?

Member

rbtcollins commented Jul 28, 2015

@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/test_cli.py ?

@vitalybe

This comment has been minimized.

Show comment
Hide comment
@vitalybe

vitalybe Jul 29, 2015

perhaps print six.path

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

/usr/lib/python2.7/dist-packages/
and in
/usr/local/lib/python2.7/dist-packages/

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

vitalybe commented Jul 29, 2015

perhaps print six.path

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

/usr/lib/python2.7/dist-packages/
and in
/usr/local/lib/python2.7/dist-packages/

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

@rbtcollins

This comment has been minimized.

Show comment
Hide comment
@rbtcollins

rbtcollins Jul 29, 2015

Member

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

Member

rbtcollins commented Jul 29, 2015

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

@grantmcconnaughey

This comment has been minimized.

Show comment
Hide comment
@grantmcconnaughey

grantmcconnaughey Jul 29, 2015

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.

grantmcconnaughey commented Jul 29, 2015

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.

@rbtcollins

This comment has been minimized.

Show comment
Hide comment
@rbtcollins

rbtcollins Jul 29, 2015

Member

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.

Member

rbtcollins commented Jul 29, 2015

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.

@jackiesyu

This comment has been minimized.

Show comment
Hide comment
@jackiesyu

jackiesyu Aug 12, 2015

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

jackiesyu commented Aug 12, 2015

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

theY4Kman added a commit to jasonkeene/python-ubersmith that referenced this issue Aug 28, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment