Cannot upgrade Pip. Permission denied. Why? - python

I'm trying to upgrade pip on my iMac, but I keep getting a permission denied error. I'm the admin, so I don't know what I've done wrong.
iMac:~ me$ pip install --upgrade pip
You are using pip version 6.0.8, however version 7.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting pip from https://pypi.python.org/packages/py2.py3/p/pip/pip-7.1.2-py2.py3-none-any.whl#md5=5ff9fec0be479e4e36df467556deed4d
Downloading pip-7.1.2-py2.py3-none-any.whl (1.1MB)
100% |################################| 1.1MB 181kB/s
Installing collected packages: pip
Found existing installation: pip 6.0.8
Uninstalling pip-6.0.8:
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-6.0.8-py2.7.egg/pip/basecommand.py", line 232, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-6.0.8-py2.7.egg/pip/commands/install.py", line 347, in run
root=options.root_path,
File "/Library/Python/2.7/site-packages/pip-6.0.8-py2.7.egg/pip/req/req_set.py", line 543, in install
requirement.uninstall(auto_confirm=True)
File "/Library/Python/2.7/site-packages/pip-6.0.8-py2.7.egg/pip/req/req_install.py", line 667, in uninstall
paths_to_remove.remove(auto_confirm)
File "/Library/Python/2.7/site-packages/pip-6.0.8-py2.7.egg/pip/req/req_uninstall.py", line 126, in remove
renames(path, new_path)
File "/Library/Python/2.7/site-packages/pip-6.0.8-py2.7.egg/pip/utils/__init__.py", line 316, in renames
shutil.move(old, new)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 300, in move
rmtree(src)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 247, in rmtree
rmtree(fullname, ignore_errors, onerror)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 252, in rmtree
onerror(os.remove, fullname, sys.exc_info())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 250, in rmtree
os.remove(fullname)
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip-6.0.8-py2.7.egg/EGG-INFO/dependency_links.txt'
I don't know what I've done wrong here as an upgrade seem fairly straightforward.
Thanks,

pip installations require elevation
sudo pip install --upgrade pip
Just because you are currently using an admin account doesn't mean the command will run with elevation, unless you specify sudo

You have to use sudo since you are upgrading pip "globally". I prefer to install Homebrew and let Homebrew manage everything.
Install Xcode from the App Store
Install Homebrew - ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Install Python - brew install python, which also installs pip.
With this setup, everything is installed locally, which doesn't require you to run sudo.
I hope this helps.

You can do one of two ways:
chown -R user /path/to/file a more detailed information can be found in this SO post, while it doesn't relate to the exact problem it deals with the same issue
Quick and dirty way just do pip install --upgrade pip as already mentioned. However, many users will suggest against that.

Related

How to solve ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org', port=443) with pip?

I recently need to install some packages
pip install future
pip install scikit-learn
pip install numpy
pip install scipy
I also tried by writin sudo before them but all it came up with the following errors in red lines:
Exception:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 290, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1198, in prepare_files
do_download,
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1376, in unpack_url
self.session,
File "/usr/lib/python2.7/dist-packages/pip/download.py", line 572, in unpack_http_url
download_hash = _download_url(resp, link, temp_location)
File "/usr/lib/python2.7/dist-packages/pip/download.py", line 433, in _download_url
for chunk in resp_read(4096):
File "/usr/lib/python2.7/dist-packages/pip/download.py", line 421, in resp_read
chunk_size, decode_content=False):
File "/usr/lib/python2.7/dist-packages/urllib3/response.py", line 256, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "/usr/lib/python2.7/dist-packages/urllib3/response.py", line 201, in read
raise ReadTimeoutError(self._pool, None, 'Read timed out.')
ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out.
Storing debug log for failure in /root/.pip/pip.log'
Use --default-timeout=100 parameter with the install:
sudo pip install --default-timeout=100 future
sudo pip install --default-timeout=100 future
or alternatively
export PIP_DEFAULT_TIMEOUT=100
worked for me on Mac OS X
They are two ways to handle this issue:
sudo pip install --default-timeout=100 future
or
pip install --default-timeout=100 future
Note: If you are not superuser of your machine, the sudo pip command will not work.
Upgrading pip solved the problem for me.
python -m pip install --upgrade pip
Just throwing this out there to avoid any confusion, for pip3 you can use
sudo pip3 install --default-timeout=100 future
If you are using JetBrains PyCharm, the appropriate solution steps are :
connect to terminal/open terminal in PyCharm.
type source <path to your projects environment eg: /users/name/myapp/venv>
Run pip install <package name> or run pip3 install <package name> as per your installation
This will automatically install package for your interpreter.
My problem was that pip couldn't load a specific version of a package, which lead to the same error message i.e. ReadTimeoutError. Try to find the failing package and update it to the latest version.

Pip version virtualenv doesn't match and won't upgrade

Okay, so, I run my project packages in a virtual environment. I usually manage these packages through PyCharm. PyCharm tells me I have Pip 9.0.1 installed. Only when I run my virtual environment from the command line and I print pip version, it says 7.1.0. If I try upgrading using pip install --upgrade pip I get an error
Collecting pip
Using cached pip-9.0.1-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 7.1.0
Uninstalling pip-7.1.0:
Successfully uninstalled pip-7.1.0
Rolling back uninstall of pip
Exception:
Traceback (most recent call last):
File "c:\python-virtualenv\arcus\lib\site-packages\pip-7.1.0-py3.5.egg\pip\basecommand.py", line 223, in main
status = self.run(options, args)
File "c:\python-virtualenv\arcus\lib\site-packages\pip-7.1.0-py3.5.egg\pip\commands\install.py", line 299, in run
root=options.root_path,
File "c:\python-virtualenv\arcus\lib\site-packages\pip-7.1.0-py3.5.egg\pip\req\req_set.py", line 646, in install
**kwargs
File "c:\python-virtualenv\arcus\lib\site-packages\pip-7.1.0-py3.5.egg\pip\req\req_install.py", line 813, in install
self.move_wheel_files(self.source_dir, root=root)
File "c:\python-virtualenv\arcus\lib\site-packages\pip-7.1.0-py3.5.egg\pip\req\req_install.py", line 1008, in move_wheel_files
isolated=self.isolated,
File "c:\python-virtualenv\arcus\lib\site-packages\pip-7.1.0-py3.5.egg\pip\wheel.py", line 449, in move_wheel_files
generated.extend(maker.make(spec))
File "c:\python-virtualenv\arcus\lib\site-packages\pip-7.1.0-py3.5.egg\pip\_vendor\distlib\scripts.py", line 323, in make
self._make_script(entry, filenames, options=options)
File "c:\python-virtualenv\arcus\lib\site-packages\pip-7.1.0-py3.5.egg\pip\_vendor\distlib\scripts.py", line 227, in _make_script
self._write_script(scriptnames, shebang, script, filenames, ext)
File "c:\python-virtualenv\arcus\lib\site-packages\pip-7.1.0-py3.5.egg\pip\_vendor\distlib\scripts.py", line 163, in _write_script
launcher = self._get_launcher('t')
File "c:\python-virtualenv\arcus\lib\site-packages\pip-7.1.0-py3.5.egg\pip\_vendor\distlib\scripts.py", line 302, in _get_launcher
result = finder(distlib_package).find(name).bytes
AttributeError: 'NoneType' object has no attribute 'bytes'
My system-wide pip version is 9.0.1 though. I just don't get what is happening. Hopefully someone can shed some light. I've tried de-installing and re-installing it again, I've tried using a wheel to install, doesn't work
Windows, by the way.
I had the same issue, but found the answer here:
https://github.com/pypa/pip/issues/2669
Basicly I just had to use this command instead:
easy_install -U pip
Open the Command Prompt (cmd) as administrator and run:
pip install --user --upgrade pip
Or try:
python -m pip install --user --upgrade pip
Relevant GitHub issue.

pip upgrade uninstalled itself

I used pip today for the first time in a while and I got the helpful message
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
So, I went ahead and
pip install --upgrade pip
but things did not go according to plan...
Collecting pip
Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
100% |████████████████████████████████| 1.3MB 510kB/s
Installing collected packages: pip
Found existing installation: pip 8.1.1
Uninstalling pip-8.1.1:
Exception:
Traceback (most recent call last):
File "//anaconda/lib/python2.7/site-packages/pip/basecommand.py", line 209, in main
status = self.run(options, args)
File "//anaconda/lib/python2.7/site-packages/pip/commands/install.py", line 317, in run
prefix=options.prefix_path,
File "//anaconda/lib/python2.7/site-packages/pip/req/req_set.py", line 726, in install
requirement.uninstall(auto_confirm=True)
File "//anaconda/lib/python2.7/site-packages/pip/req/req_install.py", line 746, in uninstall
paths_to_remove.remove(auto_confirm)
File "//anaconda/lib/python2.7/site-packages/pip/req/req_uninstall.py", line 115, in remove
renames(path, new_path)
File "//anaconda/lib/python2.7/site-packages/pip/utils/__init__.py", line 267, in renames
shutil.move(old, new)
File "//anaconda/lib/python2.7/shutil.py", line 303, in move
os.unlink(src)
OSError: [Errno 13] Permission denied: '/anaconda/lib/python2.7/site-packages/pip-8.1.1.dist-info/DESCRIPTION.rst'
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
And now it seems that pip is completely gone from my computer:
$ pip
-bash: //anaconda/bin/pip: No such file or directory
Is pip really gone, that is, did it really uninstall and then fail to reinstall, or did something just get unlinked? How can I avoid this issue in the future? Because I can imagine I will need to upgrade pip again at some point...
Python comes with a module for installing pip without needing to pull anything from the internet called ensurepip. It's pretty straightforward to use, just run the following in a terminal:
python -m ensurepip
From there you can upgrade pip to the latest the standard way. Additional documentation is available here https://docs.python.org/3/library/ensurepip.html.
You can reinstall pip with conda:
conda install pip
Looks like you need to have root rights:
sudo conda install pip
You can use curl to reinstall pip via the Python Packaging Authority website:
curl https://bootstrap.pypa.io/get-pip.py | python

upgrade pip without root access

I am trying to use pip 8 in a super computer where I don't have root access. After downloading pip from:
https://pip.pypa.io/en/stable/installing/
I do:
myname#edison04:~/software/pip> python get-pip.py --prefix=~/local_python_lib/
Collecting pip
Using cached pip-8.0.3-py2.py3-none-any.whl
Collecting wheel
Using cached wheel-0.29.0-py2.py3-none-any.whl
Installing collected packages: pip, wheel
Found existing installation: pip 1.5.4
Uninstalling pip-1.5.4:
Exception:
Traceback (most recent call last):
File "/tmp/tmplu5E1W/pip.zip/pip/basecommand.py", line 209, in main
status = self.run(options, args)
File "/tmp/tmplu5E1W/pip.zip/pip/commands/install.py", line 317, in run
prefix=options.prefix_path,
File "/tmp/tmplu5E1W/pip.zip/pip/req/req_set.py", line 725, in install
requirement.uninstall(auto_confirm=True)
File "/tmp/tmplu5E1W/pip.zip/pip/req/req_install.py", line 752, in uninstall
paths_to_remove.remove(auto_confirm)
File "/tmp/tmplu5E1W/pip.zip/pip/req/req_uninstall.py", line 115, in remove
renames(path, new_path)
File "/tmp/tmplu5E1W/pip.zip/pip/utils/__init__.py", line 266, in renames
shutil.move(old, new)
File "/usr/common/usg/python/2.7.9/lib/python2.7/shutil.py", line 300, in move
rmtree(src)
File "/usr/common/usg/python/2.7.9/lib/python2.7/shutil.py", line 247, in rmtree
rmtree(fullname, ignore_errors, onerror)
File "/usr/common/usg/python/2.7.9/lib/python2.7/shutil.py", line 252, in rmtree
onerror(os.remove, fullname, sys.exc_info())
File "/usr/common/usg/python/2.7.9/lib/python2.7/shutil.py", line 250, in rmtree
os.remove(fullname)
OSError: [Errno 13] Permission denied: '/global/common/edison/usg/python/2.7.5/lib/python2.7/site-packages/pip-1.5.4-py2.7.egg/pip/__init__.py'
You are using pip version 1.5.4, however version 8.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
It tries to remove the already existing pip which I don't want to (and I don't have permissions to).... May I ask what can i do? Thank you.
A few more updates: adding --user does not help:
myname#edison04:~/software/pip> python get-pip.py --prefix=~/local_python_lib/ --user
ERROR: Can not combine '--user' and '--prefix' as they imply different installation locations
You are using pip version 1.5.4, however version 8.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
myname#edison04:~/software/pip> python get-pip.py --user
Collecting pip
Using cached pip-8.0.3-py2.py3-none-any.whl
Installing collected packages: pip
Successfully installed pip-1.5.4
You are using pip version 1.5.4, however version 8.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
This installs pip-1.5.4 on some location, however I want to use pip 8.0.3 instead... Further more, when i locate the installed pip, and try to check their version... I think it just links my local bin to the pip 1.5.4 global bin
key01027#edison04:~> find . -name "pip"
./software/pip
./local_python_lib/pip
./.local/bin/pip
./.local/edison/2.7.9/lib/python2.7/site-packages/pip
./.local/edison/2.7.9/bin/pip
./.cache/pip
key01027#edison04:~> cd .local/
key01027#edison04:~/.local> cd bin/
key01027#edison04:~/.local/bin> ls
pip pip2 pip2.7
key01027#edison04:~/.local/bin> ./pip --version
pip 1.5.4 from /global/common/edison/usg/python/2.7.5/lib/python2.7/site-packages/pip-1.5.4-py2.7.egg (python 2.7)
key01027#edison04:~/.local/bin> ./pip2 --version
pip 1.5.4 from /global/common/edison/usg/python/2.7.5/lib/python2.7/site-packages/pip-1.5.4-py2.7.egg (python 2.7)
key01027#edison04:~/.local/bin> ./pip2.7 --version
pip 1.5.4 from /global/common/edison/usg/python/2.7.5/lib/python2.7/site-packages/pip-1.5.4-py2.7.egg (python 2.7)
What could I do? Thank you
further, using virtual env also does not solve this problem:
After set up the virtualenv, it also does not help...
(dev)key01027#edison08:~/software> which pip
/global/homes/k/key01027/dev/bin/pip
(dev)key01027#edison08:~/software> pip install --upgrade pip
Cannot fetch index base URL https://pypi.python.org/simple/
Could not find any downloads that satisfy the requirement pip in /global/common/edison/usg/python/2.7.5/lib/python2.7/site-packages/pip-1.5.4-py2.7.egg
Downloading/unpacking pip
Cleaning up...
No distributions at all found for pip in /global/common/edison/usg/python/2.7.5/lib/python2.7/site-packages/pip-1.5.4-py2.7.egg
Storing debug log for failure in /global/homes/k/key01027/.pip/pip.log
Python Virtual Environments solve this problem by allowing you to segment off your project's dependencies from others on the same system.
Most locked down systems still provide virtualenv, if not - contact your system administrator.
http://docs.python-guide.org/en/latest/dev/virtualenvs/
https://pypi.python.org/pypi/virtualenv

Using --prefix when upgrading python packages

The --prefix option to setup.py (and pip via --install-option) seems broken.
I need to maintain a shared repository of updated python packages on a machine where I do not have sudo access. Theoretically the --prefix option to setup.py (and pip the via --install-option) can do what I need.
However if there is already a version of the package I am installing in the system directories, I cannot install it on my private repository. Installing without --upgrade fails because a package already exists in the system, and installing with --upgrade fails because the old package version cannot be removed. This is shown in the error message below.
Is there any way to prevent install from trying to remove the old version of a package? OR, more likely, am I just not understanding how this is supposed to work?
$ pip --version
pip 1.5.6 from /python-local/lib/python2.7/site-packages (python 2.7)
$ pip install -U --install-option="--prefix=/python-local" virtualenv
Downloading/unpacking virtualenv from https://pypi.python.org/packages/py2.py3/v/virtualenv/virtualenv-1.11.6-py2.py3-none-any.whl#md5=c2aa2fc4986967815f8cb3a3418e6031
Downloading virtualenv-1.11.6-py2.py3-none-any.whl (1.6MB): 1.6MB downloaded
Installing collected packages: virtualenv
Found existing installation: virtualenv 1.7.1.2
Uninstalling virtualenv:
Cleaning up...
Exception:
Traceback (most recent call last):
File "/python-local/lib/python2.7/site-packages/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/python-local/lib/python2.7/site-packages/pip/commands/install.py", line 283, in run
requirement_set.install(install_options, global_options, root=options.root_path)
File "/python-local/lib/python2.7/site-packages/pip/req.py", line 1431, in install
requirement.uninstall(auto_confirm=True)
File "/python-local/lib/python2.7/site-packages/pip/req.py", line 598, in uninstall
paths_to_remove.remove(auto_confirm)
File "/python-local/lib/python2.7/site-packages/pip/req.py", line 1836, in remove
renames(path, new_path)
File "/python-local/lib/python2.7/site-packages/pip/util.py", line 295, in renames
shutil.move(old, new)
File "/usr/lib/python2.7/shutil.py", line 300, in move
os.unlink(src)
OSError: [Errno 13] Permission denied: '/usr/bin/virtualenv'
Storing debug log for failure in /home/user/.pip/pip.log
The answer is to use pip's --ignore-installed option. You must use this option whenever a read-only version of the package you are installing is visible in the current environment. This includes when using --user, --local, or --prefix, and also if you are installing into a virtualenv that was created with --system-site-packages
You can find this option mentioned at the very end of this section http://pip.readthedocs.org/en/latest/user_guide.html#user-installs
or with pip install --help

Categories

Resources