pythonpython-3.xpippython-watchdog

How to fix ‘“ERROR: Command errored out with exit status 1:” when trying to install watchdog using pip


I am revisiting the python language and experiencing difficulty setting up my environment.

I am using - Mac Mojave (10.14) - python 2.7.10 (packaged with the system) - python 3.7.4 (installed using homebrew) - homebrew 2.1.14 - pip 19.2.3

I encounter an error message when attempting to install watchdog via pip. I believe the error is caused by pip attempting to install in python 2.7 folders (without sufficient permissions) instead of the python 3 folder

I have tried uninstalling, reinstalling and upgrading python 3

I encounter the following error message when attempting to install watchdog via pip

 1 error generated.
    Error compiling module, falling back to pure Python
    running install_lib
    creating /Library/Python/2.7/site-packages/yaml
    error: could not create '/Library/Python/2.7/site-packages/yaml': Permission denied
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/4d/spq3r5t92654252ql994_l540000gr/T/pip-install-nqmq6O/PyYAML/setup.py'"'"'; __file__='"'"'/private/var/folders/4d/spq3r5t92654252ql994_l540000gr/T/pip-install-nqmq6O/PyYAML/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/4d/spq3r5t92654252ql994_l540000gr/T/pip-record-g8Qjzh/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.

Solution

  • When you run pip install, exactly which pip gets used depends on several things like your PATH, shell, shell configuration, and operating system.

    The best thing to do is invoke pip using <python> -m pip where <python> is the Python that you want to install the package for. For example, if you run python3 to use the Python that you want to install the package for, then run python3 -m pip.

    If you're running python3 -m pip install ... and getting permission errors, then you can execute python3 -m pip install --user ..., which will install it to your user site-packages directory and available when you execute python3 under your user.