pip upgrade uninstalled itself - python

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

Related

Python3: Trying to upgrade pip3 in Ubuntu 16.04 but it doesn't update

Basically, the title. I want to upgrade pip because I cannot get new packages in python because it is obsolete.
When I try to run pip3 install --upgrade pip from the Ubuntu terminal, this happens:
Collecting pip
Using cached pip-9.0.3-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 9.0.1
Uninstalling pip-9.0.1:
Successfully uninstalled pip-9.0.1
Rolling back uninstall of pip
Exception:
Traceback (most recent call last):
File "/home/marcell/.local/lib/python3.5/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/home/marcell/.local/lib/python3.5/site-packages/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/home/marcell/.local/lib/python3.5/site-packages/pip/req/req_set.py", line 784, in install
**kwargs
File "/home/marcell/.local/lib/python3.5/site-packages/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/home/marcell/.local/lib/python3.5/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/home/marcell/.local/lib/python3.5/site-packages/pip/wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "/home/marcell/.local/lib/python3.5/site-packages/pip/wheel.py", line 316, in clobber
ensure_dir(destdir)
File "/home/marcell/.local/lib/python3.5/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "/usr/lib/python3.5/os.py", line 241, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.5/dist-packages/pip'
You are using pip version 9.0.1, however version 9.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
How should I solve this problem? I tried to purge pip and reinstall it,but to no avail.
Edit: Also, tried the upgrade command with pip too, but it didn't seem to work.
I have two solutions to your problem
Try using sudo as stated in above answer.
sudo pip3 install --upgrade pip
Try to do fresh reinstall of pip
apt-get remove python3-pip
pip3 install -U pip
NOTE: This can be done for python2x ,by replace pip3 by pip2
Try:
sudo pip3 install --upgrade pip
"Permission denied" errors are usually solved by adding "sudo" to your commands.
(sudo is just a keyword to execute a given command with privileges)
If you get a "command not found" then you should do the following:
Type Python into your command console, it will tell you which version of Python you are using.
C:/>python
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32
If you have Python 3.x you should use pip3, if you have Python 2.x you should use pip.
If you are using the right pip but still get the "command not found" then you have to install pip:
For Python2.x:
sudo apt-get install python-pip
For Python 3.x:
sudo apt-get install python3-pip

Jupyter install fails on Mac

I'm trying to install Jupyter on my Mac (OS X El Capitan) and I'm getting an error in response to:
sudo pip install -U jupyter
At first the download/install starts fine, but then I run into this:
Installing collected packages: six, singledispatch, certifi, backports-abc, tornado, jupyter-core, pyzmq, jupyter-client, functools32, jsonschema, nbformat, pygments, mistune, MarkupSafe, jinja2, nbconvert, path.py, pickleshare, simplegeneric, setuptools, gnureadline, appnope, ptyprocess, pexpect, ipython, ipykernel, terminado, notebook, ipywidgets, jupyter-console, qtconsole, jupyter
Found existing installation: six 1.4.1
DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
Uninstalling six-1.4.1:
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 209, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 317, in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 726, in install
requirement.uninstall(auto_confirm=True)
File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 746, in uninstall
paths_to_remove.remove(auto_confirm)
File "/Library/Python/2.7/site-packages/pip/req/req_uninstall.py", line 115, in remove
renames(path, new_path)
File "/Library/Python/2.7/site-packages/pip/utils/__init__.py", line 267, in renames
shutil.move(old, new)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
copy2(src, real_dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
copystat(src, dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/tmp/pip-ByX5xW-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'
What can I do to fix this?
The default OS X Python that El Capitan ships with is unfortunately rather badly mispackaged (grrr, Apple). Not only have they shipped some rather strange 3rd party packages already installed, but strange (old) and beta versions of those packages. Furthermore, they are heavily system protected.
This makes the default python rather unfriendly to do work with (as you have found out). In your specific case, juypter would like to install a recent version of the six library, but the system installed version is a strange old one and will not let pip update it (jupyter requires an updated version).
In general, to alleviate all future headaches, I recommend getting a different distribution of python, and putting that on your path so it is your new default. There are a couple of choices; what's important is only using one at a time (otherwise they're apt to confuse eachother, or confuse you).
Python.org - From the Python developers themselves
Homebrew - a unixy package manager for OS X, which has a normally-functioning python package
Anaconda Python - A scientific python distribution, with many 'harder-to-install' scientific packages already available and 'just working' (including jupyter).
I recommend going with Anaconda for now, if you don't know what to choose.
Or you could just try
sudo pip install -U jupyter --upgrade --ignore-installed six
This command will install jupyter for the currently logged in user, without ignoring anything:
sudo pip install --user jupyter
Ivo's answer is correct - the best solution is to repair your python installation. An example using Homebrew (which I highly recommend) is below:
Install Homebrew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update
brew upgrade
Install Python:
brew install python
or Python 3:
brew install python3
Upgrade/install:
pip install --upgrade pip setuptools
Install jupyter:
pip install jupyter
Note: you might need to use sudo -H with pip install

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

Pip list crashes with an AssertionError

What might be the problem below? It looks like there is a bug in pip.
I installed pip yesterday using brew. Prior to that, I had installed
most python packages with $ python setup.py install
steves-MacBook-Pro:server steve$ pip -V
pip 1.4.1 from /Library/Python/2.7/site-packages/pip-1.4.1-py2.7.egg (python 2.7)
steves-MacBook-Pro:server steve$ pip list
altgraph (0.9)
bdist-mpkg (0.4.4)
...
...(a bunch of python packages omitted here for brevity)
...
...
requests (2.0.0)
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-1.4.1-py2.7.egg/pip/basecommand.py", line 134, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-1.4.1-py2.7.egg/pip/commands/list.py", line 80, in run
self.run_listing(options)
File "/Library/Python/2.7/site-packages/pip-1.4.1-py2.7.egg/pip/commands/list.py", line 127, in run_listing
self.output_package_listing(installed_packages)
File "/Library/Python/2.7/site-packages/pip-1.4.1-py2.7.egg/pip/commands/list.py", line 136, in output_package_listing
if dist_is_editable(dist):
File "/Library/Python/2.7/site-packages/pip-1.4.1-py2.7.egg/pip/util.py", line 347, in dist_is_editable
req = FrozenRequirement.from_dist(dist, [])
File "/Library/Python/2.7/site-packages/pip-1.4.1-py2.7.egg/pip/__init__.py", line 194, in from_dist
assert len(specs) == 1 and specs[0][0] == '=='
AssertionError
Using modern Ubuntu, I had the same problem and was able to fix it using the instructions in this comment.
The problem, as I understand it, is that pip as provided by Ubuntu is old, and also cannot update itself (since it's managed by apt, not pip). One solution is to remove the Ubuntu version of pip and install the latest.
In short:
sudo apt-get remove python-pip
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
This will install pip to /usr/local/bin, so you'll want to add that to your path.
This can be caused by an old version of pip.
Make sure your setuptools and pip are up to date:
sudo pip install --upgrade setuptools
sudo pip install --upgrade pip

Categories

Resources