Search code examples
python-2.7unit-testingpippython-importimporterror

pip install mock works but import mock does not


Python 2.7.9 (client requirement), Windows 10

'pip install mock' says it worked

But no mock!

Other modules install and run fine (e.g. coverage) so I'm sure my paths are setup properly

Does mock not install/run on 2.7.9? Having trouble finding requirements for this module.

>pip list
coverage (5.3)
pip (1.5.6)
setuptools (7.0)
UNKNOWN (4.0.2)

>pip install mock
Downloading/unpacking mock
  Running setup.py (path:c:\users\user\appdata\local\temp\pip_build_user\mock\setup.py) egg_info for package mock

Installing collected packages: mock
  Running setup.py install for mock

Successfully installed mock
Cleaning up...

>pip list
coverage (5.3)
pip (1.5.6)
setuptools (7.0)
UNKNOWN (4.0.2)

>python
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import mock
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named mock

Thanks!


Solution

  • you're using a very old version of pip / setuptools which doesn't understand mock's wheels or python_requires or packaging metadata

    I'd suggest upgrading pip to at least version 9.0.3 (where python_requires was introduced)

    I'd suggest upgrading setuptools to at least version 30.3 (where declarative metadata (setup.cfg) was introduced)