Search code examples
pythonunit-testingpippython-mock

pip install -U mock : Error


I am trying to install mock for unit test a class in Python. I used the following command on terminal to install mock:

$ sudo pip install -U mock

I am getting the following error:

OSError: [Errno 1] Operation not permitted: '/tmp/pip-4u8kWt-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'

I am refererring to this in order to learn mocking for Python unit testing: https://myadventuresincoding.wordpress.com/category/python/

I have Python 2.7.10 installed.

How can I resolve this error?


Solution

  • You must be running El Capitan.

    From the following link:

    This is because OS X El Capitan ships with six 1.4.1 installed already and when it attempts to uninstall it (because your package depends on six > 1.4.1) it doesn't have permission to do so because System Integrity Protection doesn't allow even root to modify those directories.

    On most systems though, you'll likely want to use virtualenv to create a custom environment and install dependencies for each project. This prevents you from trying to install things into the system version of python which may affect how your system runs.

    cd source/directory
    virtualenv env
    . ./env/bin/activate
    pip install mock
    

    This also has the added benefit that each project can have it's own dependencies and you don't have to worry about version conflicts between projects.