[python] 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.

This question is related to python macos pip

The answer is


Regarding the permissions command, try using sudo in front of your terminal command:

sudo pip install --upgrade pip

Sudo allows you to run the command with the privileges of the superuser and will install the package for the global, system-wide Python installation. Ideally, you should create a virtual environment for the project you are working on. Have a look at this

Regarding the python Try running pip as an executable like this:

python3.6 -m pip install <package>

I was making the same mistakes then I realized that I have created my virtual environment as root user. It was write protected, so please check whether your virtual environment is write protected. make a new venv and try again


On Mac, there is no 3.7 directory or the directory 3.7 is owned by root. So, I removed that directory, create a new directory by current user, and move it there. Then installation finishes without error.

sudo rm -rf /Library/Python/3.7
mkdir 3.7
sudo mv 3.7 /Library/Python
ll /Library/Python/
pip3 install numpy

just sudo pip install packagename


I had similar trouble in a venv on a mounted NTFS partition on linux with all the right permissions. Making sure pip ran with --ignore-installed solved it, i.e.:

python -m pip install --upgrade --ignore-installed


I have anaconda installed for Python 3. I also have Python2 in my mac.

python --version

gives me

Python 3.7.3

python2.7 --version

gives me

Python 2.7.10

I wanted to install pyspark package in python2, given that it was already installed in python3.

python2.7 -m pip install pyspark

gives me an error

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pyspark' Consider using the --user option or check the permissions.

The below command solved it. Thank god I didn't have to do any config changes.

python2.7 -m pip install pyspark --user

Collecting pyspark Requirement already satisfied: py4j==0.10.7 in /Library/Python/2.7/site-packages (from pyspark) (0.10.7) Installing collected packages: pyspark Successfully installed pyspark-2.4.4 You are using pip version 18.1, however version 19.3.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command.


I already tried all suggestion posted in here, yet I'm still getting the errno 13,

I'm using Windows and my python version is 3.7.3

After 5 hours of trying to solve it, this step worked for me:

I try to open the command prompt by run as administrator


I had the same problem while installing numpy with pip install numpy.

Then I tried

sudo -H pip3 install --upgrade pip

sudo -H pip3 install numpy

It worked well for me.

Explanation : The -H (HOME) option with sudo sets the HOME environment variable to the home directory of the target user (root by default). By default, sudo does not modify HOME.


The answer is in the error message. In the past you or a process did a sudo pip and that caused some of the directories under /Library/Python/2.7/site-packages/... to have permissions that make it unaccessable to your current user.

Then you did a pip install whatever which relies on the other thing.

So to fix it, visit the /Library/Python/2.7/site-packages/... and find the directory with the root or not-your-user permissions and either remove then reinstall those packages, or just force ownership to the user to whom ought to have access.


I got the same error when I was trying to install a package (flask-classful).
I made the mistake of installing anaconda as root. I changed the ownership of the installed anaconda folder and I could install the package successfully.

Use the command chown with option -R to recursively change ownership of the installed anaconda folder like so:

chown -R owner:group /path/to/anaconda

Here owner is your username and group is the group name.


This also happens to me when I try to install the opencv-python package:

installation attempt

I can fix it with command line

python3 -m pip install {name of package} --user

When I try to install the said package, the command becomes:

python3 -m pip install opencv-python --user

Resulting in this:

result


I also had the same problem, I tried many different command lines, this one worked for me:

Try:

    conda install py-xgboost

That's what I got:

Collecting package metadata: done
Solving environment: done

## Package Plan ##

  environment location: /home/simplonco/anaconda3

  added / updated specs:
    - py-xgboost


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    _py-xgboost-mutex-2.0      |            cpu_0           9 KB
    ca-certificates-2019.1.23  |                0         126 KB
    certifi-2018.11.29         |           py37_0         146 KB
    conda-4.6.2                |           py37_0         1.7 MB
    libxgboost-0.80            |       he6710b0_0         3.7 MB
    mkl-2019.1                 |              144       204.6 MB
    mkl_fft-1.0.10             |   py37ha843d7b_0         169 KB
    mkl_random-1.0.2           |   py37hd81dba3_0         405 KB
    numpy-1.15.4               |   py37h7e9f1db_0          47 KB
    numpy-base-1.15.4          |   py37hde5b4d6_0         4.2 MB
    py-xgboost-0.80            |   py37he6710b0_0         1.7 MB
    scikit-learn-0.20.2        |   py37hd81dba3_0         5.7 MB
    scipy-1.2.0                |   py37h7c811a0_0        17.7 MB
    ------------------------------------------------------------
                                           Total:       240.0 MB

The following NEW packages will be INSTALLED:

  _py-xgboost-mutex  pkgs/main/linux-64::_py-xgboost-mutex-2.0-cpu_0
  libxgboost         pkgs/main/linux-64::libxgboost-0.80-he6710b0_0
  py-xgboost         pkgs/main/linux-64::py-xgboost-0.80-py37he6710b0_0

The following packages will be UPDATED:

  ca-certificates     anaconda::ca-certificates-2018.12.5-0 --> pkgs/main::ca-certificates-2019.1.23-0
  mkl                                            2019.0-118 --> 2019.1-144
  mkl_fft                              1.0.4-py37h4414c95_1 --> 1.0.10-py37ha843d7b_0
  mkl_random                           1.0.1-py37h4414c95_1 --> 1.0.2-py37hd81dba3_0
  numpy                               1.15.1-py37h1d66e8a_0 --> 1.15.4-py37h7e9f1db_0
  numpy-base                          1.15.1-py37h81de0dd_0 --> 1.15.4-py37hde5b4d6_0
  scikit-learn                        0.19.2-py37h4989274_0 --> 0.20.2-py37hd81dba3_0
  scipy                                1.1.0-py37hfa4b5c9_1 --> 1.2.0-py37h7c811a0_0

The following packages will be SUPERSEDED by a higher-priority channel:

  certifi                                          anaconda --> pkgs/main
  conda                                            anaconda --> pkgs/main
  openssl                anaconda::openssl-1.1.1-h7b6447c_0 --> pkgs/main::openssl-1.1.1a-h7b6447c_0


Proceed ([y]/n)? y


Downloading and Extracting Packages
libxgboost-0.80      | 3.7 MB    | ##################################### | 100% 
mkl_random-1.0.2     | 405 KB    | ##################################### | 100% 
certifi-2018.11.29   | 146 KB    | ##################################### | 100% 
ca-certificates-2019 | 126 KB    | ##################################### | 100% 
conda-4.6.2          | 1.7 MB    | ##################################### | 100% 
mkl-2019.1           | 204.6 MB  | ##################################### | 100% 
mkl_fft-1.0.10       | 169 KB    | ##################################### | 100% 
numpy-1.15.4         | 47 KB     | ##################################### | 100% 
scipy-1.2.0          | 17.7 MB   | ##################################### | 100% 
scikit-learn-0.20.2  | 5.7 MB    | ##################################### | 100% 
py-xgboost-0.80      | 1.7 MB    | ##################################### | 100% 
_py-xgboost-mutex-2. | 9 KB      | ##################################### | 100% 
numpy-base-1.15.4    | 4.2 MB    | ##################################### | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

This worked for me:

 python3 -m venv env
 source ./env/bin/activate
 python -m pip install package

(From Github: https://github.com/googlesamples/assistant-sdk-python/issues/236 )


For MacOs & Unix

Just by adding sudo to command will work, as it would run it as a superuser.

sudo pip install --upgrade pip

It is advised that you should not directly do it though - please see this post


try this command line below for MacOS to check user's permission.

$ sudo python -m pip install --user --upgrade pip

Examples related to python

programming a servo thru a barometer Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? python variable NameError Why my regexp for hyphenated words doesn't work? Comparing a variable with a string python not working when redirecting from bash script is it possible to add colors to python output? Get Public URL for File - Google Cloud Storage - App Engine (Python) Real time face detection OpenCV, Python xlrd.biffh.XLRDError: Excel xlsx file; not supported Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation

Examples related to macos

Problems with installation of Google App Engine SDK for php in OS X dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac Could not install packages due to an EnvironmentError: [Errno 13] How do I install Java on Mac OSX allowing version switching? Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Can't compile C program on a Mac after upgrade to Mojave You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user) How can I install a previous version of Python 3 in macOS using homebrew? Could not install packages due to a "Environment error :[error 13]: permission denied : 'usr/local/bin/f2py'"

Examples related to pip

How to fix error "ERROR: Command errored out with exit status 1: python." when trying to install django-heroku using pip "E: Unable to locate package python-pip" on Ubuntu 18.04 How to Install pip for python 3.7 on Ubuntu 18? What is the meaning of "Failed building wheel for X" in pip install? Could not install packages due to an EnvironmentError: [Errno 13] How do I install Python packages in Google's Colab? Conda version pip install -r requirements.txt --target ./lib pip: no module named _internal AttributeError: Module Pip has no attribute 'main' Error after upgrading pip: cannot import name 'main'