Python - PIP install trouble shooting - PermissionError: [WinError 5] Access is denied
Asked Answered
C

24

99

I get the following error when using PIP to either install new packages or even upgrade pip itself to the latest version. I am running pip on a windows 8.1 machine with Python 3.4.

The message is telling me I don't have Administrative Permission on the files (my account is an Administrator Account).

I would appreciate any thoughts on how to resolve this, as it is getting in the way of installing packages and progressing with Python.

Error message:

Installing collected packages: pip
  Found existing installation: pip 6.0.8
    Uninstalling pip-6.0.8:
      Removing file or directory c:\program files (x86)\python\python34\lib\site-packages\pip-6.0.8.dist-info\description.rst
      Cleaning up...
Exception:
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python\Python34\lib\shutil.py", line 523, in move
    os.rename(src, real_dst)
PermissionError: [WinError 5] Access is denied: 'c:\\program files (x86)\\python\\python34\\lib\\site-packages\\pip-6.0.8.dist-info\\description.rst' -> 'C:\\Users\\User\\AppData\\Local\\Temp\\pip-uze_sc4k-uninstall\\program files (x86)\\python\\python34\\lib\\site-packages\\pip-6.0.8.dist-info\\description.rst'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Python\Python34\lib\site-packages\pip\basecommand.py", line 232, in main
    status = self.run(options, args)
  File "C:\Program Files (x86)\Python\Python34\lib\site-packages\pip\commands\install.py", line 347, in run
    root=options.root_path,
  File "C:\Program Files (x86)\Python\Python34\lib\site-packages\pip\req\req_set.py", line 543, in install
    requirement.uninstall(auto_confirm=True)
  File "C:\Program Files (x86)\Python\Python34\lib\site-packages\pip\req\req_install.py", line 667, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "C:\Program Files (x86)\Python\Python34\lib\site-packages\pip\req\req_uninstall.py", line 126, in remove
    renames(path, new_path)
  File "C:\Program Files (x86)\Python\Python34\lib\site-packages\pip\utils\__init__.py", line 316, in renames
    shutil.move(old, new)
  File "C:\Program Files (x86)\Python\Python34\lib\shutil.py", line 536, in move
    os.unlink(src)
PermissionError: [WinError 5] Access is denied: 'c:\\program files (x86)\\python\\python34\\lib\\site-packages\\pip-6.0.8.dist-info\\description.rst'
Coshow answered 23/8, 2015 at 13:57 Comment(6)
Run the command prompt as administrator. Might help. Having administrator permissions in the account is not always enough.Hydrogenize
Thanks Roope. This was indeed the issue. Easily solved but frustrating to experience.Coshow
Still relevant in 2018: don't run things as admin. The -by far- more sensible solution is to use virtualenv to create a virtual environment directory ("virtualenv dirname") and then activate that virtual environment with "dirname\Script\Activate" before running any pip commands. That way, everything gets written to dirs that you have full write permission for, without needing UAC, and without global installs for local dependencies.Mortal
It works for me when i've run cmd in administrator mode.Stricture
might be that Users group don't have permissions to write/modify for the C: drive, and this error will pop up even if you are logged in as admin, so you could check the permissions for the C: drive for the Users group.Kegler
Does this answer your question? pip install access denied on WindowsGleiwitz
H
86

E: Since this answer seems to have gained some popularity, I will add: doing things globally is most of the time not a great idea. Almost always the correct answer is: use a project environment where you're not installing things globally, e.g. with virtualenv.


For those that may run into the same issue:

Run the command prompt as administrator. Having administrator permissions in the account is not always enough. In Windows, things can be run as administrator by right-clicking the executable and selecting "Run as Administrator". So, type "cmd" to the Start menu, right click cmd.exe, and run it as administrator.

Hydrogenize answered 25/8, 2015 at 8:53 Comment(7)
If you don't have administrator privileges/don't want administrator privileges: #7465945Duncan
it still occurred even in admin modeAymara
Still relevant in 2018: the by far more sensible solution is to create a virtualenv with "virtualenv dirname", and then activate it with "dirname\Script\Activate" before running any pip commands.Mortal
I encountered the same error message "PermissionError: [WinError 5] Access is denied" when trying to upgrade pip using the command "python -m pip install --upgrade pip" and when trying to install numpy using the command "pip install numpy". i followed the above method by opening and running the cmd window as Administrator, and ran the said installations. it worked.Bethink
For those still asking themselves in 2018 why virtualenv is a more sensible solution than running pip as an administrator: "Everything seems fine, but we've unknowingly created a disaster!" dabapps.com/blog/introduction-to-pip-and-virtualenv-pythonFoiled
One more: "Usually pip and virtualenv are the only two packages you ever need to install globally, because once you've got both of these you can do all your work inside virtual environments." Quoted from the same link as above.Foiled
If issue persists while using admin mode on Windows, try closing all command line prompts. It happened to me that I had another command line open with the virtual environment activated, and closing everything and starting in a new command line prompt helped me solve the issuePatrinapatriot
F
71

I know my answer would be weird but that's what I have experienced just now.

I got the similar error when installing tensorflow package and I tried the same by opening powershell in windows as administrator but in vain.

Later I found out that I was already using numpy in one of the python scripts in an active python session. So I closed the Spyder IDE and tried to install the tensorflow package by running powershell as administrator and it worked.

Hope this will help somebody else like me who will open this older but useful post in upcoming days

Finnegan answered 12/11, 2017 at 17:46 Comment(8)
Thanks, this helped me out. Additionally i found Spyder to broken because what i tried earlier. This was fixed by running 'conda install tornado=4.5.3'' as suggested in github.com/spyder-ide/spyder/issues/6426Jacqulynjactation
I had a running jupyter notebook. Closing it fixed the problem.Impound
I too had this problem , I just closed the already running window and tried again , this solved the pbmHermie
Been online searching for 20 minutes, this is the only thing that worked for me! thanks.Root
This worked, I had jupyter notebook running in another session. After I killed it, I was able to uninstall.Sarinasarine
This worked for me, I was facing the same problem even after running as administratior, closing already running window helpedFarrahfarrand
Yep, same problem. I had a jupyter notebook running on that environment. And after closing the session could install the req.txt file :/Wilone
Was running FastAPI in my IDE, myself. I was not able to run pip even in an Admin Powershell instance. Then I saw this answer and put two and two together.Jeremy
S
31

Even you run from Administrator, it may not solve the issue if the pip is installed inside another userspace. This is because Administrator doesn't own another's userspace directory, thus he can't see (go inside) the inside of the directory that is owned by somebody. Below is an exact solution.

python -m pip install -U pip --user //In Windows 

Note: You should provide --user option

pip install -U pip --user //Linux, and MacOS
Stat answered 16/8, 2018 at 4:20 Comment(1)
it returns this ERROR: Can not perform a '--user' install. User site-packages are not visible in this virtualenv.Acherman
P
10

For those who run into this issue and running the command prompt as administrator does not work this worked for me:

Since I had already tried a first time without running the cmd prompt as admin, in my c:\Users\"USER"\AppData\Local\Temp folder I found it was trying to run files from the same pip-u2e7e0ad-uninstall folder. Deleting this folder from the Temp folder and retrying the installation fixed the issue for me.

Photomicroscope answered 21/4, 2018 at 18:4 Comment(3)
This did not work for me on Windows 10 with Anaconda. Deleting all C:\\Users\\...\\AppData\\Local\\Temp\\pip-unpack- did not change anything for me.Mime
THIS. especially on domain joined mwin machinesParrotfish
This worked to fix the problem when I was using a virtualenv. (Windows 10)Clavius
O
6

Do not use the command prompt in the IDE. Run the command prompt from windows as an administrator. I'm sure this will solve the problem. If not, uninstall pip and reinstall the latest one directly.

Omura answered 25/6, 2016 at 12:25 Comment(1)
I managed to do it from the IDE (PyCharm). I just restarted PyCharm itself in administrator mode.Gyration
E
6

As of upgrading from pip 7.x.x to 8.x.x on Python 3.4 (for *.whl support).

Wrong command: pip install --upgrade pip (can't move pip.exe to temporary folder, permisson denied)

OK variant: py -3.4 -m pip install --upgrade pip (do not execute pip.exe)

Emarie answered 25/6, 2016 at 15:18 Comment(1)
Thank you. So the problem is that pip can't be moved temporarily due to it being executed as a program!Benjy
M
5

I have had the same problem with anaconda on windows. It seems that there is an issue with McAfee antivirus. If you deactivate it while running the updates or the installation, it allows you to run the installation.

Megganmeggi answered 6/10, 2016 at 0:42 Comment(1)
Disabling "Host IPS" helped me. Thanks!Seaver
Q
5

After seeing

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

I ran

pip install -U pip

and hit this error

PermissionError: [WinError 5]

I tried again and got

pip install -U pip
ERROR: To modify pip, please run the following command:
c:\python36-32\python.exe -m pip install -U pip

After running that exact command, it worked.

For those promoting the use of virtual environments as a solution to this error, pip and virtualenv must be updated in your main install. Simply put, a virtual environment offers no solution to this problem.

Quipster answered 7/6, 2018 at 22:28 Comment(1)
This had to be this way because your C:\Users\user\AppData\Roaming\Python\Python36\Scripts folder is not in the environment's PATH.You
G
4

TL;DR: python -m pip install -U pip, then try again.


I was already using a venv (virtualenv) in PyCharm.

Creating it I clicked inherit global site packages checkbox, to allow packages installed via an installer to work. Now inside my venv there was no pip installed, so it would use the inherited global pip.

Here is how the error went:

(venv) D:\path\to\my\project> pip install certifi  # or any other package

Would fail with

PermissionError: [WinError 5] Access denied: 'c:\\program files\\python36\\Lib\\site-packages\\certifi'

Notice how that is the path of the system python, not the venv one. However we want it to execute in the right environment.

Here some more digging:

(venv) D:\path\to\my\project> which pip
/c/Program Files/Python36/Scripts/pip

(venv) D:\path\to\my\project> which python
/d/path/to/my/project/venv/Scripts/python

So python is using the correct path, but pip is not? Let's install pip here in the correct one as well:

(venv) D:\path\to\my\project> python -m pip install -U pip
... does stuff ...
Successfully installed pip

Now that's better. Running the original failing command again now works, as it is using the correct pip.

(venv) D:\path\to\my\project> pip install certifi  # or any other package
... install noise ...
Successfully installed certifi-2019.9.11 chardet-3.0.4 idna-2.8 requests-2.22.0 urllib3-1.25.7
Gardner answered 23/11, 2019 at 14:20 Comment(2)
Thank you. Why python -m pip install -U pip worked please?Went
@Avra The OS has no idea pip is installed. So we tell the python process to load the module (-m) with the name pip and then run install -U pip with it. The python interpreter's pip then will make the pip command available to the OS by putting a link into a folder which is available in $PATH where your shell will look for it when you next type pip install …. See the documentation for entry_points of any installable python package if you want to learn more on that.Gardner
A
1

Still relevant in 2018: don't install packages as admin.

The by far more sensible solution is to use virtualenv to create a virtual environment directory (virtualenv dirname) and then activate that virtual environment with dirname\Script\Activate in Windows before running any pip commands. Or use pipenv to manage the installs for you.

That way, everything gets written to dirs that you have full write permission for, without needing UAC, and without global installs for local directories.

Athirst answered 13/2, 2018 at 17:40 Comment(4)
It's the third time in same question you are posting this suggestions/comment. I admire your persistence, but what's the point?Chokebore
Perhaps that you should use virtualenv, and that the other answers I commented are, are fairly insane given the Windows user rights models. Even if it's an old question, with old answers, leave new comments if answers no longer work for "now" (although admittedly, even back in 2015, the answer really was "use virtualenv"). Really bad advice is worse than no advice, leave comments when you see answers (or other comments) that will lead to disaster.Mortal
Honestly some users like me don't require multiple python installations. We're perfectly happy running a single installation and can manage the dependencies just fine like that, and we see no need for an extra command of "virtualenv" to activate if our only goal is to use a single python installation. I'm puzzled why using the default Python windows installer issues like this must persist. If running python natively on windows is not supported then the official installer should say so, otherwise a specific solution to the problem is all that's desired.Nepos
Then I hope you don't ever need to run anyone else's code, which will yield version conflicts once you've run pip to install things globally. This has f'all to do with "purists" and everything to do with applying some common sense about conflicting software requirements in an ecosystem where that problem has been solved in about as non-intrusive a way as possible (pipenv ain't perfect, but it's a whole lot better than manually install every single requirement yourself, with manual _un_installing of packages that conflict every single time you need to run someone else's code).Mortal
I
1

Note that if you are installing this through Anaconda, you will need to open Anaconda as an administrator and then launch the command prompt from there.

Otherwise, you can also run "Anaconda prompt" directly as an administrator to uninstall and install packages.

Irma answered 26/1, 2019 at 3:40 Comment(0)
P
1

Was facing this issue on windows when upgrading pip inside a virtual environment so in a loaded venv try

python -m pip install --upgrade pip

instead of using normal command like

pip install --upgrade pip #X

Can't use --user here, as we are in venv

Polluted answered 6/8, 2021 at 22:41 Comment(0)
F
1

This error I had on different times and misleading was solved today inspired from the running notebooks comments up there... I had my PyCharm updating skeletons on my newly installed env/packages at the same time! Closing PyCharm and rerunning the pip install was alright (from inside my anaconda prompt) !!

Frieda answered 20/11, 2023 at 14:51 Comment(0)
G
0

I ran into this issue when I was using pycharm to create and run a virtual environment - I clicked the "inherit global site packages" checkbox - deleting and recreating the venv solved the issue for me. If you used another means for creating your venv, make sure it IS NOT INHERITING global packages! enter image description here

Garlan answered 10/5, 2019 at 18:20 Comment(0)
B
0

I have the same error. Not sure why it happened. But I managed to upgrade by running:

pip install setuptools --upgrade --ignore-installed

After that, I used a PowerShell or Command Prompt - cmd in administrator mode to install the package:

pip install the-package

# or
easy_install the-package

Also, what they have already suggested: Installing packages using pip and virtual environments , which is the best practice for new projects.

Bashkir answered 23/1, 2021 at 12:18 Comment(0)
M
0

I had the same problem and I used these steps to solve it.

  1. I added the path into "system environment variables".
  2. I changed the "Registry editor". In order to do that, type "regeidt" in run, then open the "Registry editor". Go to "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem", choose "LongPathsEnabled" and change the "Valuedata" to "1" press the "Ok", and restart the computer.
  3. Run "Command Prompt" as an "administrator" and type "pip install scikit-learn".
Mealtime answered 28/7, 2021 at 21:39 Comment(0)
E
0

In my case, when I went into the properties of AppData folder, there were two checked check-boxes - one for 'Read-Only' and one for 'hidden'. I unchecked the 'hidden' option. It took 5 minutes to process. After that, I was able to install the packages successfully from cmd in administrator mode.

Eleusis answered 11/10, 2021 at 17:51 Comment(0)
K
0

Below worked for me

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

Kingdom answered 18/12, 2021 at 14:19 Comment(0)
D
0

Working inside a venv in Windows 10 that I received the error when using the PowerShell terminal inside VS Code. When using the command prompt terminal pip was upgraded successfully.

Desegregate answered 21/1, 2022 at 19:59 Comment(0)
Q
0

I had a similar problem after upgrading my python installation (with scoop). The problem in my case was that the pip configuration was messed up:

pip config list                                                                                                   
global.target='C:/Program Files/Python310/Lib/site-packages'
global.trusted-host='pypi.python.org\npypi.org\nfiles.pythonhosted.org'

so I had to manually edit the global.target in the pip configuration.

pip config set global.target C:\Users\[User]\scoop\apps\python\current\Lib\site-packages
Quadrat answered 23/1, 2023 at 7:59 Comment(0)
B
0

I just had a similar problem.

ERROR: Could not install packages due to an OSError: [WinError 5]  Access is denied: 'C:\\Users\\Lenovo\\Documents\\STUDIES\\venv\\Lib\\site-packages\\matplotlib\\ft2font.cp311-win_amd64.pyd'
Check the permissions

The error occurred when I was trying to reinstall the matplotlib package. Beside, my VS Code was running with opened jupyter notebook, where one of cells contains:

import matplotlib as plt

The solution was to close the VS Code.

The point is, maybe try to close all programs that use the package that you want to install.

Bowen answered 18/3, 2023 at 12:2 Comment(0)
V
0

TL;DR: Before upgrading pip, remove and re-create the venv.


The most of answers recommend to fix the issue with command: `python -m pip install --upgrade pip`

In general, this is the proper solution with some caveats.

It is bad practice to use general Python environment. Good practice is using virtual environment per every project. This answer is for people who encounter the Permission denied problem and use venv.

I messed up with my venv until the upgrading pip command was failing with Unable to locate pip command error. My solution was:

  1. Remove the existing venv from the project.
  2. Create new venv.
  3. python -m pip install --upgrade pip
  4. Install project requirements. In my case pip install -r requirements.txt but you can install packages manually too.
Vardhamana answered 3/11, 2023 at 15:24 Comment(0)
T
0

I had this problem in 2024 on a Windows machine and none of the above solutions helped.

What solved it for me was checking the permissions of my venv and project directory. Somehow, it was marked at read-only. After unchecking the read-only box, I was able to pip install the missing packages.

directory properties

Telemechanics answered 28/2 at 12:13 Comment(0)
C
-1

Just reinstall Python in another folder, e.g. c:\python. After that you won't be bothered by pip wanted administrator privileges.

Windows 10 Pro x64 user.

Caravan answered 8/7, 2018 at 16:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.