Solving Python Error – Could not install packages due to an EnvironmentError: [Errno 13] Permission denied

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied is a Python error which occurs when you do not install a package correctly

In this article I am going to try and solve the error while I try to explain why the error is actually popping up, we will also introduce some solutions that worked for other developers and see if those solutions can solve the error in your particular situation.

Explaining the Error : Could not install packages due to an EnvironmentError: [Errno 13] Permission denied

First we should understand that the error is a Python error which occurs when you do not install a package correctly

Let us start by checking out the message of the error bellow, make sure your error matches this one in order to avoid any kind of confusion

                                                                       #
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.
                                                                       #

Bellow you can find the solution which worked for me plus other popular possible solutions among developers who already faced this error.

Solution 1 : use pip3

The first solution is to use pip3 to install packages Just like in the example bellow

                                                                       #
pip3 install package_name
                                                                       #

Solving the error ‘errno 13’ is done by modify the command above a little bit Just like in the example bellow

                                                                       #
pip3 install package_name --user
                                                                       #

The solution above should be enough to solve the problem. if that is not the case, try the solution bellow

Solution 2 : use a virtual environment

The second solution is to use a virtual environment

You can create a virtual environment by using the command bellow

                                                                       #
virtualenv enviroment_name -p python3
                                                                       #

then activating it with

                                                                       #
source enviroment_name/bin/activate
                                                                       #

Make sure the virtual environment is active then run this command to install the package

                                                                       #
pip install package_name
                                                                       #

The solutions above should be enough to solve the problem, if you like our effort make sure to consider donating to our Kofi account, there is a red button that you can use if you are feeling generous.

Summing-up

The end, we arrived at the end of this article, I hope my article helped you solve your issue, I am sure there are at least 10 other reasons why this error occurs, I can not find them all and explain them, this is my best attempt guys.

Thank you for reading, cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/