pythonmacospip

Could not install packages due to an EnvironmentError: [Errno 13]


In my MacOS Mojave terminal I wanted to install a python package with pip. At the end it says:

You are using pip version 10.0.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

So I wanted to update pip with the given command but I got an error:

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: 
'/Library/Python/2.7/site-packages/pip-18.0-py2.7.egg/EGG-INFO/PKG-INFO'
Consider using the `--user` option or check the permissions.

I don't really understand what to do now. Also I realized it says Python 2.7 in the error message but I have and want to use only python 3.


Solution

  • If you want to use python3+ to install the packages you need to use pip3 install package_name

    And to solve the errno 13 you have to add --user at the end

    pip3 install package_name --user
    

    EDIT:

    For any project in Python it's highly recommended to work on a Virtual environment, which is a tool that helps to keep dependencies required by different projects separate by creating isolated Python virtual environments for them.

    In order to create one with python3+ you have to use the following command:

    virtualenv enviroment_name -p python3
    

    And then you work on it just by activating it:

    source enviroment_name/bin/activate
    

    Once the virtual environment is activated, the name of your virtual environment will appear on the left side of the terminal. This will let you know that the virtual environment is currently active. Now you can install dependencies related to the project in this virtual environment by just using pip.

    pip install package_name