PermissionError: [Errno 13] Permission Denied while Running as Admin - python

So I get the following error whenever I try to install pip in my cmd for Windows while running as admin:
Everywhere I've looked says you can fix the problem by just running as admin but when I did it still did not work

I think, there's some problem with python or you've messed up things i.e deleted or moved some critical files. First verify python and pip installation by, typing this in cmd-
python -V
pip -V
If your version comes as an output then don't worry. I think you want to upgrade pip. Type this in cmd to upgrade pip-
python -m pip install --upgrade pip
And if not. Since the problem is not clear to me i.e what actually happened. I'll recommend reinstallation. Open Setting>Apps and features. Select Python and click Uninstall. After successful uninstallation. Go to the link below to download the latest version of Python-
https://www.python.org/downloads/release/python-396/
Scroll down and select Windows Installer(64 bit). Download the installer and double-click on it. You can uncheck the box, Install for other users if you want. Don't uncheck the box which says Add python to PATH. Click on Install Now.
After successful installation, verify that python and pip are correctly installed or not. By typing executing these to commands(one by one)-
python -V
pip -V
Congratulations, Python has been successfully re-installed.

Related

How can I uninstall a corrupted PIP instance on Windows?

Today, I was trying to install Python 3.10.1.
I was successful in this, but, then, as I was installing Flask, pip will tell me that it installed, then, when I run the script, it says nothing is installed.
After a while, I realized I was running my Python scripts in Python 3.10.1, but I was running pip in Python 3.7. I did as this post said and ran pip --version to discover this.
I ran pip show flask to see where the module is, and it's in the Python 3.7 folder.
However, when I tried to uninstall Python 3.7, I can't find it in my start menu or in Control Panel > Programs > Programs & Features. I believe I had uninstalled it a long time ago.
To counteract this, I did as some YouTube video said (I lost the link to it) and re-installed Python 3.10.1, checked the "Add to PATH" option, checked to install for all users, and checked on the pip install.
After doing this, I upgraded my pip version to the latest version, uninstalled Flask, and re-installed it.
It was still installed in the Python 3.7 folder.
Next, I decided I will just uninstall PIP.
I ran CMD as an Administrator and typed pip uninstall pip as instructed here.
However, when I did this, it says I'm missing access to the places it wants to modify.
I found that strange, so I checked if I'm actually running it Administrator, and, yes, I am.
I looked at the directories that it wants to modify and gave ADMINISTRATORS ownership of all of them.
Absolutely nothing changed and did it again.
I gave myself ownership of it and did it again.
Absolutely nothing changed.
Then, I decided to run pip uninstall pip again. It says pip is not installed. That's strange.
I typed pip, and the help command for pip shows up.
Then, I (probably stupidly) went to all the directories and files PIP listed that it wants to uninstall, and manually deleted them, then uninstalled Python 3.10.1, and made sure to install PIP from there.
And now we're back at Python 3.7, and pip still isn't installed somehow.
I don't know what's happening. I haven't coded anything in Python for 2 or 3 years, and I want to try again, but this is starting to confuse me. Could anyone help?
Edit: Based on the suggestion of one of the answerers, I tried to manually delete pip. I couldn't find it in %APPDATA%, but pip --version shows me the path.
I tried deleting pip from there, but it says I need permission from ADMINISTRATORS. I am an administrator on my computer -.-
Anyways, I tried to take ownership of the folder, but nothing ever came of that.
Try to locate %APPDATA%\pip\pip by typing it into the file explorer. Pip will be located there, and you should be able to delete it.
I've managed to fix the issue.
I found that if I press this button in the start menu search for Python 3.7, it's possible to uninstall it from there (Control Panel said it uninstalled it when I used that, but it didn't).
I think I had installed Python from the Microsoft Store, which is why I couldn't find it in %APPDATA%.
Once I did that, I tried to uninstall Python 3.10 then re-install it. It kept saying it's installed, but it wouldn't show up in Command Prompt.
I fixed this by installing Python 3.10 from the Microsoft Store instead.
This fixed the problem.

permission denied when installing python packages through cygwin

I'm working on a windows 7 and using Cygwin for unix-like functionality. I can write and run Python scripts fine from the Cygwin console, and the installation of Python packages using pip installis successful and the installed package appears under pip list. However, if I try to run a script that imports these packages, for example the 'aloe' package, I get the error "no such module named 'aloe'".
I have discovered that the packages are being installed to c:\python27\lib\site-packages, i.e. the computer's general list of python packages, and not to /usr/lib/python3.6/site-packages, i.e. the list of python packages available within Cygwin. I don't know how to rectify this though. If I try to specify the install location using easy_install-3.6 aloe I get the error
[Errno 13] Permission denied: '/usr/lib/python3.6/site-packages/test-easy-install-7592.write-test'.
In desperation also tried directly copying the 'aloe' directory to the Cygwin Python packages directory using cmd with cp -r \python27\lib\site-packages\aloe \cygwin\lib\python3.6\site-packages and the move was successful, but the problem persists and when I check in the Cygwin console using ls /usr/lib/python3.6/site-packages I can't see 'aloe'.
I have admin rights to the computer in general (sudo is not available in Cygwin anyway) so really can't figure out what the problem is. Any help would be greatly appreciated.
Thanks.
just make sure you are in admin mode.
i.e. right click on Cygwin, select running as administrator.
then install your package specifically using pip3, for python3.
i.e. pip3 install your_package
with updated version, do pip3 install --upgrade your_package

pip freeze doesn't show anything in Windows installation?

I have Python27 installed in Windows 7
I am trying to build a reddit bot using this tutorial
I found instructions on how to install pip for windows from here
The page says that after installing pip, I can use pip freeze to check if the installation went correctly
It says pip freeze should display some information as shown below
Microsoft Windows [Version 6.2.9200] (c) 2012 Microsoft Corporation.
All rights reserved.
C:\Users\Username>cd c:\Python27\Scripts
c:\Python27\Scripts>pip freeze
antiorm==1.1.1
enum34==1.0
requests==2.3.0 virtualenv==1.11.6
However pip freeze doesn't show me anything at all
Did pip install correctly, or is there any problem? Is there any other way i can test proper installation?
If you want to test it thoroughly, you can use your actual pip installation to install something. For example, numpy would be a good sized example that can rule many problems out.
> pip install numpy
Now, run pip freeze again to check if pip is working as expected. It should then have something to show.
If you want to test it even further, you can open a terminal and
> python
> import numpy
That should be the complete test of your pip installation.
Additionally, whenever I install a new tool in my stack, I like to validate its path with where <executable name> (on Windows) and which <executable name> (on Linux). There are some compilers like Java that are always conflicting with other installations (like crazy, to the point that a complex setup may sometimes have to inject an absolute path to enforce the use of the correct version).
Also, asking the executable for its version can rule many other problems out. In your case, you can use pip --version to check which version you got and compare it to the stable or latest, according to what you want to use.
windows is a confusing piece of software if your coming from a Linux background... the solution that worked for me is the following
pip list
The problem you are facing is that if you only have de default packages in your installation lets say pip, wheel, pip freeze does not have anything to freeze at the moment so that's why dont show anything. try to install a new package then run the command again.

Can't use pip to install flask [duplicate]

I have installed python 3.5 on my Windows 7 machine. When I installed it, I marked the check box to install pip. After the installation, I wanted to check whether pip was working, so I typed pip on the command line and hit enter, but did not respond. The cursor blinks but it does not display anything.
Please help.
Regards.
Add the Script folder of python to your environment path
or you can do this from command line:
python -m pip install package-name
go the windows cmd prompt
go to the python directory
then type python -m pip install package-name
run it at the cmd window, not inside the python window. it took me forever to realize my mistake.
I was having the same problem on Windows 10, This is how I fix it:
Click the search icon and type System Environment
In System Properties click on Environment Variables
In System Variables tab click New
Enter PYTHON3_SCRIPTS for the variable name and C:\Users\YOUR USER NAME\AppData\Local\Programs\Python\Python38-32\Scripts for Variable Value. Don't forget to change (YOUR USER NAME) in the path with your user, And to change your Python version or just go to this path to check it C:\Users\YOUR USER NAME\AppData\Local\Programs\Python
Click OK
Click NEW again!
Enter PYTHON3_HOME for the variable name and C:\Users\YOUR USER NAME\AppData\Local\Programs\Python\Python38-32\ for Variable Value. Don't forget to change (YOUR USER NAME) in the path with your user, And to change your Python version or just go to this path to check it C:\Users\YOUR USER NAME\AppData\Local\Programs\Python
Click OK
Find Path in the same tab select it and click Edit
Click New and type %PYTHON3_SCRIPTS% Then click OK
Now, everything is set. Restart your Terminal and pip should be working now.
I had the same problem with Version 3.5.2.
Have you tried py.exe -m install package-name? This worked for me.
As soon as you open a command prompt, use:
python -m pip install --upgrade pip
then
python -m pip install <<package-name>>
If you are working in Pycharm, an easy way is go to file>setting>project interpreter. Click on the + icon you will find on right side probably and then search and install required library.
For those with several python versions of python 3 installed in windows: I solved this issue by executing the pip install command directly from my python35 Scripts folder in cmd...for some reason pip3 pointed to python 34 even though python 35 was set first in environmental variables.
I had the issue, and answered this same question sometimes ago. Do open a cmd if in windows OS or linux OS with admistrative privilege. Then python -m pip install --upgrade pip
then
python -m pip install <>
Working on windows and above version than 3.0
First upgrade pip to pip3 by following command:
pip3 install --upgrade setuptools pip
Then install maximum package by following command:
pip3 install <package_name>
I never wrote all package because some package not support to pip or pip3 command.

pip install access denied on Windows

I am trying to run pip install mitmproxy on Windows, but I keep getting access denied, even with cmd and PowerShell using the Run as Administrator option.
WindowsError: [Error 5] Access is denied: 'c:\\users\\bruno\\appdata\\local\\temp\\easy_install-0fme6u\\cryptography-0.9.1\\.eggs\\cffi-1.1.2-py2.7-win-amd64.egg\\_cffi_backend.pyd'
How can I make this work?
For Windows, in Command Prompt (Admin) try to run pip install using the Python executable:
python -m pip install mitmproxy
This should work, at least it worked for me for other package installation.
Change your Python installation folder's security permissions by:
Open a Python shell
Go to task manager
Find the python process
Right-click and open location
The folder will open in explorer, go up a directory
Right-click the folder and select properties
Click the security tab and hit 'edit'
Add everyone and give them permission to Read and Write.
Save your changes
If you open cmd as admin; then you can do the following:
If Python is set in your PATH, then:
python -m pip install mitmproxy
Personally, I found that by opening cmd as admin then run
python -m pip install mitproxy
seems to fix my problem.
Note:- I installed python through chocolatey
One additional thing that has not been covered in previous answers and that often cause issues on Windows and stopped me from installing some package despite running as admin is that you get the same permission denied error if there is another program that use some of the files you (or pip install) try to access. This is a really stupid "feature" of Windows that pops up many times, e.g. when trying to move some files.
In addition I have no clue how to figure out which program locks a particular file, so the easiest ting to do is to reboot and do the installation before starting anything, in particular before running e.g. Spyder or any other Python-based software. You can also try to close all programs, but it can be tricky to know which one actually holds a file. For a directory for example, it is enough that you have an Explorer window open at that directory.
As, i am installing through anaconda Prompt .In my case, it didn't even work with python -m pip install Then, i add this
python -m pip install <package_name> --user
It works for me.
Like: python -m pip install mitmproxy --user
Another you should try that run the Command Prompt as Run as Administrator and then try pip install. It should work either.
Open cmd with "Run as administrator" and execute the command pip install mitmproxy. It will install it.
Try to give permission to full control the python folder.
Find the python root directory-->right button click-->properties-->security-->edit-->give users Full Control-->yes and wait the process finished.
It works for me.
The cause in my case was having a jupyter notebook open, which was importing the relevant library; the root cause seems to be windows error due to the file being open / in use (see also #Robert's answer, and the recommendation to reboot).
So another thing to verify is that no other python processes are running.
For me, shutting down the notebook server solved the issue.
Try to delete the folder c:\\users\\bruno\\appdata\\local\\temp\\easy_install-0fme6u manually and then retry the pip command.
When all else fails, try quitting your IDE. I had many cases in which PyCharm was causing this. As soon as I quit PyCharm, I was able to finally install my packages from the command line. Alternatively, you can also install through PyCharm itself in Settings -> Project: xxx -> Project Interpreter -> +.
Opening command prompt As Administrator just worked for me without using Python executable.
Right click on command prompt shortcut and choose "Run as Administrator".
Then run the following command.
pip install Django
In my case,
Windows Defender is blocking the process and every time I run a pip command it will show pop up of security threat.
What I do is exclude the python folder.
Below are the steps:
Click the Windows icon, search "Windows Security" app, and open it
Choose Virus & threat protection on the left menu
Scroll down to Virus & threat protection settings
Click Manage settings
Scroll down to Exclusions
Click Add or remove exclusions
Click Add an exclusion, and choose Folder
Navigate to this path C:\Users{Your_User}\AppData\Local\Programs\Python
Select folder
Relaunch your Command prompt
Sometimes you just need to make sure you do not have any python environments running.
I met a similar problem.But the error report is about
[SSL: TLSV1_ALERT_ACCESS_DENIED] tlsv1 alert access denied (_ssl.c:777)
First I tried this https://python-forum.io/Thread-All-pip-install-attempts-are-met-with-SSL-error#pid_28035 ,but seems it couldn't solve my problems,and still repeat the same issue.
And Second if you are working on a business computer,generally it may exist a web content filter(but I can access https://pypi.python.org through browser directly).And solve this issue by adding a proxy server.
For windows,open the Internet properties through IE or Chrome or whatsoever ,then set valid proxy address and port,and this way solve my problems
Or just adding the option pip --proxy [proxy-address]:port install mitmproxy.But you always need to add this option while installing by pypi
The above two solution is alternative for you demand.
In my case, it didn't even work with python -m pip install
What I have done is, from a cmd as administrator:
PsExec.exe -i -s -d cmd.exe
In order to spawn a SYSTEM cmd, then pip install mitmproxy
;)
Open Command Prompt as Administrator.
To Install any Python Package use this command including --user.
pip install --ignore-installed --upgrade --user <packagename>
Had the same problem when installing pycaret.
I've solved in two different ways (that I'll list below).
Option 1
Upgraded pip with
python -m pip install --user --upgrade pip
Then
pip install --user pycaret[full]
Found a relevant discussion on the error here.
Option 2
Assuming one is using Anaconda, open Anaconda prompt, for the environment one is working with, as admin
And run
pip install --user pycaret[full]
or
pip install pycaret[full]
I also work in secure environment, Hence for install module I use this code:-
pip install --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org
in last add your library name , such as :
pip install --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org numpy
Run cmd.exe as an administrator then type:
python -m pip install
Running cmd as administrator solved for me. You can also try --user.
If you do not want to repeat the steps you need to give full access to anaconda folder.
Just close all the python files opened. And try to run as administrator. It will work.
e.g.
pip install mitmproxy

Categories