Related
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'
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.
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
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
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.
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.
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)
I have had the same problem with anaconda on windows. It seems that there is an issu with mcAfee antivirus. If you deactivate it while running the updates or the installs, it allows you to properly run the installation.
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.
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
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.
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.
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
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!
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.
I had the same problem and I used these steps to solve it.
I added the path into "system environment variables".
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.
Run "Command Prompt" as an "administrator" and type "pip install scikit-learn".
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.
Below worked for me
$ python -m pip install --user --upgrade pip
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.
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
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.
I'm trying to install via pip some libraries but I'm having some problems.
When I try to install some of them I require for my project I get this message:
$ sudo pip install dj-database-url==0.2.0
Downloading/unpacking dj-database-url==0.2.0
Downloading dj-database-url-0.2.0.tar.gz
Cleaning up...
setuptools must be installed to install from a source distribution
It also happens when trying to install distribute==0.6.24
Any ideas?
Download ez_setup.py module from https://pypi.python.org/pypi/setuptools
Open a Terminal.
cd to the directory where you put the ez_setup.py.
Type python ez_setup.py and run it.
You should have it then.
After a pip install command I was getting the same error as you ("setuptools must be installed to install from a source distribution"). Since I couldn't find a solution, it was a lot faster to reinstall the virtual environment where python was running from.
If you're using virtualenvwrapper this is very easy. First you remove your problematic virtual environment (let's say it is called "venv") with:
rmvirtualenv venv
Then you setup a new one with the same name:
mkvirtualenv venv
And finally you install all your packages, including the one you had problems with:
pip install dj-database-url
I have python2.6 as my default python and I've been using distribute easy_install to install packages in ~/.local. easy_install has many issues and I'd like to switch to pip, while at the same time upgrading to python2.7 from python2.6. My existing pip version is tied to python2.6 and always looks in ~/.local/lib/python2.6 for packages. This means I have to install pip again with Python2.7 but it seems like this cannot be done with the existing python2.6 pip, right?
Therefore I tried to download pip and install it like this:
python2.7 setup.py install --prefix=~/.local
Note that I do not have root, so I have to install pip locally. When I try this I get:
Traceback (most recent call last):
File "setup.py", line 5, in <module>
from setuptools import setup
ImportError: No module named setuptools
How can I fix this situation? I obviously cannot install setuptools with pip, because I can't install pip... all I want to do is link up pip with python2.7, upgrade pip and then install everything with pip and forget about easy_install and the old python2.6 and its packages.
When I try the answer below, I get:
The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/home/user/.local/lib/python2.7/site-packages
This directory does not currently exist. Please create it and try again, or
choose a different installation directory (using the -d or --install-dir
option).
I had to manually create (with mkdir) the directory:
~/.local/lib/python2.7/site-packages
This seems broken... it worked once I did it, but why does it require manual creation of a directory?
thanks.
You need to install setuptools first; it has it's own installation script (it's part of the egg file):
wget "http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg"
sh setuptools-0.6c11-py2.7.egg --prefix=~/.local
Note that it, too, supports a --prefix= option. It'll find your python2.7 binary (and not the 2.6 version) because you downloaded the 2.7 egg version.
I installed python26 using macports, so the correct python on my system is /opt/local/bin/python
However, when I do
sudo pip install <packagename>
It gives me
sudo pip install <somepackage>
Exception:
Traceback (most recent call last):
File "/Library/Python/2.6/site-packages/pip-1.0.1-py2.6.egg/pip/basecommand.py", line 126, in main
self.run(options, args)
File "/Library/Python/2.6/site-packages/pip-1.0.1-py2.6.egg/pip/commands/install.py", line 215, in run
import setuptools
ImportError: No module named setuptools
Storing complete log in /Users/navin/.pip/pip.log
And so, I suspect that it is using the system python. I've installed distribute (which contains setuptools) via their site instructions. I installed pip via an installer as well. I somehow managed to clobber the setuptools for the system python I think, so that's why I'm having this problem now :(
What do I do to get pip working again?
UPDATE: I strongly recommend installing CPython by building from source (example), and then creating virtual environments to work in.
Summarizing the above, installing pip using Macports:
sudo port install py39-pip
results in an installation of a MacPorts port named py39-pip.
However, no /opt/local/bin/pip is installed and port select pip or port select py27-pip both fail (in contrast to port select python). Changing things in the bin directory of another distribution is not recommended.
Note that Python files in:
/usr/bin are of the preinstalled Python of macOS
/usr/local/bin are installed by MacPython, available from python.org
/opt/local/bin are installed by MacPorts.
The actual executable files can be found by ls -ls applied to the various Python-related symbolic links found in each of the above bin directories).
To ensure that the Python installed by MacPorts is called first, place /opt/local/bin within the runtime environment's PATH earlier than /usr/bin and /usr/local/bin. This can be done in the file ~/.bash_profile or the file ~/.bashrc (which one depends on your system and configuration). For example, writing
export PATH=/opt/local/bin:$PATH
last in ~/.bashrc will have this effect (assuming that the intended shell will source the file ~/.bashrc).
After the paths have been appropriately defined, the system still fails to find a pip command in the Macports bin directory, because it is installed as /opt/local/bin/pip3.9. The file /opt/local/bin/pip is not automatically created.
As a result, the system continues searching the PATH, and if e.g. MacPython is added to the path some place later and has pip installed, then that pip will show up.
This can be avoided by the command proposed above:
sudo ln -s /opt/local/bin/pip3.9 /opt/local/bin/pip
Remove pip from /usr/local/bin with sudo rm /usr/local/bin/pip.
If you have installed pip with macports, which pip should then show /opt/local/bin/pip. If not, install pip again by following the instructions here. As long as which python shows the /opt/local installation, it should work. If it doesn't, you will need to edit your PATH env variable.
Here is my setup to get pip working with macports and set py26-pip as the default pip
sudo port install py26-pip && sudo port select --set pip py26-pip
after install finishes run to see the help information for pip
pip --help
after you may need to update your path to include the bin files installed by pip edit .bash_profile to include something like
export PATH=/opt/local/bin:/opt/local/sbin:/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin:$PATH
You should have the python and pip installed in /opt/local/bin/ prior to those installed in /usr/local/bin/.
Also, you should check to execute which python and whether the pip was installed in /opt/local/bin/pip.
I found I needed to ln -s /opt/local/bin/pip-2.7 /opt/local/bin/pip. For some reason macports didn't built that link, even when you try activating that version of python or pip.
I have installed a python package with python setup.py install.
How do I uninstall it?
Note: Avoid using python setup.py install use pip install .
You need to remove all files manually, and also undo any other stuff that installation did manually.
If you don't know the list of all files, you can reinstall it with the --record option, and take a look at the list this produces.
To record a list of installed files, you can use:
python setup.py install --record files.txt
Once you want to uninstall you can use xargs to do the removal:
xargs rm -rf < files.txt
Or if you're running Windows, use Powershell:
Get-Content files.txt | ForEach-Object {Remove-Item $_ -Recurse -Force}
Then delete also the containing directory, e.g. /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/my_module-0.1.egg/ on macOS. It has no files, but Python will still import an empty module:
>>> import my_module
>>> my_module.__file__
None
Once deleted, Python shows:
>>> import my_module
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'my_module'
For me, the following mostly works:
have pip installed, e.g.:
$ easy_install pip
Check, how is your installed package named from pip point of view:
$ pip freeze
This shall list names of all packages, you have installed (and which were detected by pip).
The name can be sometime long, then use just the name of the package being shown at the and after #egg=. You can also in most cases ignore the version part (whatever follows == or -).
Then uninstall the package:
$ pip uninstall package.name.you.have.found
If it asks for confirmation about removing the package, then you are lucky guy and it will be removed.
pip shall detect all packages, which were installed by pip. It shall also detect most of the packages installed via easy_install or setup.py, but this may in some rare cases fail.
Here is real sample from my local test with package named ttr.rdstmc on MS Windows.
$ pip freeze |grep ttr
ttr.aws.s3==0.1.1dev
ttr.aws.utils.s3==0.3.0
ttr.utcutils==0.1.1dev
$ python setup.py develop
.....
.....
Finished processing dependencies for ttr.rdstmc==0.0.1dev
$ pip freeze |grep ttr
ttr.aws.s3==0.1.1dev
ttr.aws.utils.s3==0.3.0
-e hg+https://vlcinsky#bitbucket.org/vlcinsky/ttr.rdstmc#d61a9922920c508862602f7f39e496f7b99315f0#egg=ttr.rdstmc-dev
ttr.utcutils==0.1.1dev
$ pip uninstall ttr.rdstmc
Uninstalling ttr.rdstmc:
c:\python27\lib\site-packages\ttr.rdstmc.egg-link
Proceed (y/n)? y
Successfully uninstalled ttr.rdstmc
$ pip freeze |grep ttr
ttr.aws.s3==0.1.1dev
ttr.aws.utils.s3==0.3.0
ttr.utcutils==0.1.1dev
Edit 2015-05-20
All what is written above still applies, anyway, there are small modifications available now.
Install pip in python 2.7.9 and python 3.4
Recent python versions come with a package ensurepip allowing to install pip even when being offline:
$ python -m ensurepip --upgrade
On some systems (like Debian Jessie) this is not available (to prevent breaking system python installation).
Using grep or find
Examples above assume, you have grep installed. I had (at the time I had MS Windows on my machine) installed set of linux utilities (incl. grep). Alternatively, use native MS Windows find or simply ignore that filtering and find the name in a bit longer list of detected python packages.
The #1 answer has problems:
Won't work on mac.
If a file is installed which includes spaces or other special
characters, the xargs command will fail, and delete any
files/directories which matched the individual words.
the -r in rm -rf is unnecessary and at worst could delete things you
don't want to.
Instead, for unix-like:
sudo python setup.py install --record files.txt
# inspect files.txt to make sure it looks ok. Then:
tr '\n' '\0' < files.txt | xargs -0 sudo rm -f --
And for windows:
python setup.py bdist_wininst
dist/foo-1.0.win32.exe
There are also unsolvable problems with uninstalling setup.py install which won't bother you in a typical case. For a more complete answer, see this wiki page:
https://ofswiki.org/wiki/Uninstalling_setup.py_install
First record the files you have installed. You can repeat this command, even if you have previously run setup.py install:
python setup.py install --record files.txt
When you want to uninstall you can just:
sudo rm $(cat files.txt)
This works because the rm command takes a whitespace-seperated list of files to delete and your installation record is just such a list.
Now python gives you the choice to install pip during the installation (I am on Windows, and at least python does so for Windows!). Considering you had chosen to install pip during installation of python (you don't actually have to choose because it is default), pip is already installed for you. Then, type in pip in command prompt, you should see a help come up. You can find necessary usage instructions there. E.g. pip list shows you the list of installed packages. You can use
pip uninstall package_name
to uninstall any package that you don't want anymore. Read more here (pip documentation).
Not exactly answering the question, but something that helps me every day:
Install your packages with
pip install .
This puts the package in $HOME/.local. Uninstall with
pip uninstall <package_name>
The lazy way: simply uninstall from the Windows installation menu (if you're using Windows), or from the rpm command, provided you first re-install it after creating a distribution package.
For example,
python setup.py bdist_wininst
dist/foo-1.0.win32.exe
("foo" being an example of course).
Go to your python package directory and remove your .egg file,
e.g.:
In python 2.5(ubuntu): /usr/lib/python2.5/site-packages/
In python 2.6(ubuntu): /usr/local/lib/python2.6/dist-packages/
Probably you can do this as an alternative :-
1) Get the python version -
[linux machine]# python
Python 2.4.3 (#1, Jun 18 2012, 14:38:55)
-> The above command gives you the current python Version which is 2.4.3
2) Get the installation directory of python -
[linux machine]# whereis python
python: /usr/bin/python /usr/bin/python2.4 /usr/lib/python2.4 /usr/local/bin/python2.5 /usr/include/python2.4 /usr/share/man/man1/python.1.gz
-> From above command you can get the installation directory which is - /usr/lib/python2.4/site-packages
3) From here you can remove the packages and python egg files
[linux machine]# cd /usr/lib/python2.4/site-packages
[linux machine]# rm -rf paramiko-1.12.0-py2.4.egg paramiko-1.7.7.1-py2.4.egg paramiko-1.9.0-py2.4.egg
This worked for me.. And i was able to uninstall package which was troubling me :)
I think you can open the setup.py, locate the package name, and then ask pip to uninstall it.
Assuming the name is available in a 'METADATA' variable:
pip uninstall $(python -c "from setup import METADATA; print METADATA['name']")
At {virtualenv}/lib/python2.7/site-packages/ (if not using virtualenv then {system_dir}/lib/python2.7/dist-packages/)
Remove the egg file (e.g. distribute-0.6.34-py2.7.egg)
If there is any from file easy-install.pth, remove the corresponding line (it should be a path to the source directory or of an egg file).
Extending on what Martin said, recording the install output and a little bash scripting does the trick quite nicely. Here's what I do...
for i in $(less install.record);
sudo rm $i;
done;
And presto. Uninstalled.
If you still have files that are supposed to be deleted after re-installing a package, make sure the folder build is also deleted. Therefore, assuming that pkg is the package you want to delete:
rm -r $(python3 -c "import pkg; print(pkg.__path__[0] + '*' )")
rm -rf build
Obove work out for python3 and delete the package and its *.egg-info file
Install from local
python setup.py install
Uninstall from local
pip uninstall mypackage
It might be better to remove related files by using bash to read commands, like the following:
sudo python setup.py install --record files.txt
sudo bash -c "cat files.txt | xargs rm -rf"
I had run "python setup.py install" at some point in the past accidentally in my global environment, and had much difficulty uninstalling. These solutions didn't help. "pip uninstall " didn't work with "Can't uninstall 'splunk-appinspect'. No files were found to uninstall." "sudo pip uninstall " didn't work "Cannot uninstall requirement splunk-appinspect, not installed". I tried uninstalling pip, deleting the pip cache, searching my hard drive for the package, etc...
"pip show " eventually led me to the solution, the "Location:" was pointing to a directory, and renaming that directory caused the packaged to be removed from pip's list. I renamed the directory back, and it didn't reappear in pip's list, and now I can reinstall my package in a virtualenv.
I had run python setup.py install once in my PyCharm, it installs all the packages into my conda base environment. Later when I want to remove all these packages, pip uninstall does not work. I had to delete them from /anaconda3/lib/python3.7/site-packages manually :(
So I don't see the reason why they use setup.py instead of writing requirements.txt file. The requirement file can be used to install packages in virtual environment and won't mess with system python packages.
I have a develop egg link set up with python setup.py develop under a conda environment and with pip uninstall <packagename> the egg link is removed. At least in this scenario, pip uninstall is one way to do this.