25

OS: ubuntu 16.04LTS

Python: 2.7.12 + Anaconda2-4.2.0 (64 bit)

I typed pip install --upgrade $TF_BINARY_URL to install tensorflow but terminal showed that my pip verson was 8.1.1, however version 9.0.1 is available.

Then I typed pip install --upgrade pip to upgrade but it showed Requirement already up-to-date: pip in ./anaconda2/lib/python2.7/site-packages,

I still can't use pip version 9.0.1 to install tensorflow. Does anyone know what's going on ??

SiHa
  • 7,830
  • 13
  • 34
  • 43
ZongHan-Li
  • 251
  • 1
  • 3
  • 3

12 Answers12

44

sudo -H pip install --upgrade pip

sudo is "super user do". This will allow you to execute commands as a super user. The H flag tells sudo to keep the home directory of the current user. This way when pip installs things, like pip itself, it uses the appropriate directory.

Metagrapher
  • 8,602
  • 1
  • 24
  • 31
  • 1
    It is absolutely an answer to the question. If you run the command, it will install pip properly, even if pip thinks it has the most recent version. This is because it could be caused by a permissions issue, though generally one should not have to pip using sudo, sometimes it happens. – Metagrapher Dec 09 '16 at 22:09
  • 1
    I thought it wasn't a good idea to use sudo with python. Is it okay with pip ? – Revolucion for Monica May 11 '18 at 15:18
  • 1
    Usually a bad idea to use sudo with pip because of permissions, home directory, and linked binaries issues. However, in the event that your pip upgrade is not working, and it's caused by permissions issues (which can be difficult to diagnose, I've found, but open to suggestion) then this will _usually_ fix your pip installation. **It's important to keep the home directory of your current user**, however. – Metagrapher May 14 '18 at 03:13
  • discovered that as of Ubuntu 16.04 pip is aliased to pip3 so that is why both sudo and pip3 commands are working for some people. Perhaps, depending on the root cause of the issue in your case pip3 is the better command. YMMV. try `ls \`which pip\` && ls \`which pip2\` && ls \`which pip3\` ` first – Metagrapher May 14 '18 at 03:32
  • Thank you very much, what should I do if mine is : `/home/mike/.local/bin/pip /home/mike/.local/bin/pip2 /home/mike/.local/bin/pip3` ? – Revolucion for Monica May 14 '18 at 10:10
  • If they're all in your local, assuming you are `mike` on this system, you shouldn't need to use `sudo` as you should have ownership of that directory. Check your permissions with `ls -halp /home/mike/.local/bin/` to see if you are owner. If you are then there's some other issue. Try using the pip(s) directly like `$> python -m ./home/mike/.local/bin/pip3 --upgrade pip` or perhaps `$> pip2 --upgrade pip`. You may even try using `sudo apt-get update && sudo apt-get install python-pip`, though that may install yet another `pip` and re-link `$> pip` to still a different `pip`...welcome to pip hell – Metagrapher May 16 '18 at 07:37
  • `pip --version --verbose` is also your friend and may lend some insight into your specific problem. Of course, you can also do this with your individual `pip`s as in the same format as above – Metagrapher May 16 '18 at 07:37
  • Also be weary that if you are in a virtualenv you can install even yet another version of pip. On my own system just now, in order to try to answer you again, I wound up going through all these steps and still needing the original `sudo -H ...` solution in order to update to 10. I had a system pip and thusly it was owned by wheel. – Metagrapher May 16 '18 at 07:44
  • 1
    This is a great solution. Also big props on adding the -H flag, I wasn't aware of that. – Austin Aug 04 '18 at 19:27
  • solution without using sudo? – Charlie Parker Oct 20 '20 at 16:10
  • @CharlieParker I'm not aware of one. It's, sadly, kind of the point of this answer. Hopefully you have admin rights on your dev machine. I go into much detail above about why it's necessary in this specific case. Best of luck, this one can be a beast. – Metagrapher May 21 '21 at 19:13
  • @CharlieParker I see that you are on a linux HPC cluster. There is a way to get sudo to work in that instance, though it seems that you are having some other permissions issue. Perhaps check the group permissions on `which pip` ? I also go into more detail on finding permissions issues above ;) It sounds like it will be a `chown` thing, hopefully, but I don't have enough info to answer better than this. – Metagrapher May 21 '21 at 19:38
21

I had this same problem. Not sure what is going on. I use both python and python3 and have both a pip and a pip3. By chance I did the following and it seems to have fixed the problem.

pip3 install -U pip

resulting in

Collecting pip
  Using cached pip-9.0.1-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 8.1.2
Uninstalling pip-8.1.2:
  Successfully uninstalled pip-8.1.2
Successfully installed pip-9.0.1
JVSIP
  • 381
  • 1
  • 9
  • 1
    That only upgrades pip for python3 and does not answer the original question at all. – Metagrapher Dec 06 '16 at 22:32
  • since this answer has more votes than the correct answer, and because this answer is irrelevant to the asked question, I am downvoting. Sorry, thought you should know why though. – Metagrapher Dec 06 '16 at 22:35
  • 2
    Thats fine. However I tried the "correct" answer and it failed to help me. This "incorrect" answer fixed my problem. – JVSIP Dec 07 '16 at 23:34
  • It's not an issue of correct versus incorrect. It's an issue of actually adressing the OPs issue or not, which you did not, though it seems to the untrained eye that you did. Basically, you used python3 to install python2's package manager, which is super wacky btw. I would be surprised to learn that this doesn't complicate the issue for others. Glad it worked for you though. – Metagrapher Dec 09 '16 at 22:07
  • 2
    @Metagrapher - As is often the case, differing causes may result in similar problem symptoms. It seems it could be so in this case. Debugging is enhanced by keeping an open mind and examining all possibilities. – Craig Hicks Aug 13 '17 at 15:44
  • 2
    Did that work for you anyway? I needed `sudo -H ...` as the other suggested. Without, I got a PermissionError. Did you happen to change `sudoers`? – John P Jan 22 '18 at 03:21
  • I got the following: During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/bin/pip3", line 11, in load_entry_point('pip==9.0.1', 'console_scripts', 'pip3')() File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 570, in load_entry_point return get_distribution(dist).load_entry_point(group, name) File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site- – R Claven Sep 17 '18 at 18:06
21

I have the same problem. But my python is under /usr/bin. I tried sudo -H pip install -U pip, which didn't work. However, when I removed the pip installed by system package manager with

sudo apt-get remove python-pip python3-pip

, the problem was solved. It seems that pip installed with system package manager is not consistent with pip wrapped up with python.

Metagrapher
  • 8,602
  • 1
  • 24
  • 31
mt1022
  • 16,834
  • 5
  • 48
  • 71
  • 2
    Same problem for me. There seems to be a conflict between 2 pip installs ... Removing python-pip from apt, and running "pip install --upgrade pip" solvde the problem – vdechef Feb 17 '17 at 10:18
  • 1
    Good catch! I had a feeling - my pip3 finally let me upgrade pip to 9.0.1, which is only half of what I needed, but the very next command I issued complained about 8.1.2. As it turns out, they were *both* 8.1.2 still. AFAIK that means I had four Pips to go with my two Pythons, and as far as my system is concerned, they're all the real Slim Shady. Meanwhile, between the average time between updates from 2.6-3.6 and the fact that they jumped from 2.7-3.0, we could have Python 4.0 in mid-April. – John P Jan 22 '18 at 04:08
  • 1
    on a fresh install of Ubuntu16.04 LTS all this answer did was remove pip completely - so did not address the posted problem at all – KayCee Mar 07 '18 at 11:36
  • 1
    try `ls \`which pip\` && ls \`which pip2\` && ls \`which pip3\`` first. Also be careful that pip in a venv can be a different pip than outside of one...because you can have entire installs of python in venvs...which you should be compartmentalizing your dependencies. – Metagrapher May 14 '18 at 03:38
  • solution without using sudo? – Charlie Parker Oct 20 '20 at 16:11
  • 1
    @CharlieParker, I could not think of a way to remove system packages without sudo. But this problem doesn't occur when I use latest anaconda with python3. – mt1022 Oct 27 '20 at 05:44
17

For me none of the above solutions worked, except
easy_install -U pip

UPDATE: easy_install was part of python-setuptools but from version 39.0.1-2, it is no longer part of it. See changelog.

markroxor
  • 5,928
  • 2
  • 34
  • 43
  • followed by https://stackoverflow.com/a/49900741/4361073 (to solve the main import error - seemingly caused by the update request). – parasrish Oct 11 '18 at 09:56
  • @parasrish both problems are common but, independent of each other. – markroxor Oct 11 '18 at 10:08
  • 1
    This is the best answer. – Farzad Amirjavid Oct 02 '20 at 02:24
  • this seemed to download things but then pip didn't work anyway: ``` (automl-meta-learning) [miranda9@golubh1 automl-proj]$ pip install -e . Traceback (most recent call last): File "/home/miranda9/.local/bin/pip", line 5, in from pip._internal.cli.main import main ModuleNotFoundError: No module named 'pip._internal.cli.main' ``` – Charlie Parker Oct 20 '20 at 16:15
  • `(automl-meta-learning) [miranda9@golubh1 automl-proj]$ easy_install -U pip Searching for pip Reading https://pypi.python.org/simple/pip/ Downloading https://files.pythonhosted.org/packages/cb/28/91f26bd088ce8e22169032100d4260614fc3da435025ff389ef1d396a433/pip-20.2.4-py2.py3-none-any.whl#sha256=51f1c7514530bd5c145d8f13ed936ad6b8bfcb8cf74e10403d0890bc986f0033 ` – Charlie Parker Oct 20 '20 at 16:15
  • `Best match: pip 20.2.4 Processing pip-20.2.4-py2.py3-none-any.whl Installing pip-20.2.4-py2.py3-none-any.whl to /home/miranda9/.conda/envs/automl-meta-learning/lib/python3.7/site-packages Adding pip 20.2.4 to easy-install.pth file Installing pip script to /home/miranda9/.conda/envs/automl-meta-learning/bin Installing pip3 script to /home/miranda9/.conda/envs/automl-meta-learning/bin Installing pip3.8 script to /home/miranda9/.conda/envs/automl-meta-learning/bin ` – Charlie Parker Oct 20 '20 at 16:15
  • `Installed /home/miranda9/.conda/envs/automl-meta-learning/lib/python3.7/site-packages/pip-20.2.4-py3.7.egg Processing dependencies for pip Finished processing dependencies for pip` – Charlie Parker Oct 20 '20 at 16:15
9

Try updating pip using conda as follows:

conda update pip

Thereafter try installing tensorflow. See this

Psycho_Coder
  • 235
  • 2
  • 9
  • 1
    @ZongHan-Li Please select my answer as best then. – Psycho_Coder Nov 10 '16 at 06:13
  • @ZongHan-Li Please select this answer as correct so that it will float above the other incorrect answers. – Metagrapher Dec 06 '16 at 22:34
  • I think this should not be the accepted answer as in my case I wasn't using `conda` at all. Hence not a very generalized solution. – markroxor Jan 18 '18 at 07:18
  • This seems like a fantastic idea but it didn't work for me... :( – Charlie Parker Oct 20 '20 at 16:16
  • @CharlieParker conda obviates pip and provides virtual environments, so if conda works for you, then you shouldn't need to mess with pip. In fact, if you can avoid using pip for packages, do that. Often on OSX, because it ships with an OS version of python 2.7, this can be a major headache. Conda should not install pip, however. this just gives you a second install of pip. Pyenv seems to be The Way these days. https://towardsdatascience.com/which-python-package-manager-should-you-use-d0fd0789a250?gi=35c7f6d4362b – Metagrapher May 21 '21 at 19:28
5

I had same problem BUT because of permission. So simple solution for me:

sudo pip install --upgrade pip
grep
  • 5,465
  • 12
  • 60
  • 112
3

First, a discussion of the relationship between python and pip. Then how to apply that to your Anaconda - tensorflow problem.


"Pip" is a python package, meaning it must be run by a python interpreter. The file(s) you see when calling which pip (which pip3) are actually python scripts, and they are effectively aliasing as follows:

  • pip ... results in calling python2.7 -m pip ...

  • pip3 ... results in calling python3.5 -m pip ...

Furthermore, in your environment pip is the alias target of pip2,

Each version of python has it's own search path, so each version finds a different version of the pip package. Moreover,

when the python2.7/sitepackages/pip is called by python2.7, it will install in /home/<user>/.local/lib/python2.7/site-packages (or the window equivalent)

and when the python3.5/site-packages/pip is called by python3.5, it will install in /home/<user>/.local/lib/python3.5/site-packages (or the window equivalent)

It is impossible for python2.7 to call python3.5/.../pip, and impossible for python3.5 to call python2.7/.../pip - so fortunately we don't even have to consider those combinations, whew!

Why did your system not want to upgrade the pip in python2.7/.../site-packages? My guess is that was by design. By the way, are you sure tensorflow is written in python2.7 and not python3.5?


To get back to your question: I found this link which may be of interest to you:

Installing Tensorflow on windows Anaconda2

It appears that the OP was trying to use tensorflow which required python3.5, into Anaconda2 which uses python2.7.

Perhaps you could upgrade to Anaconda3 which uses python3.5? (There might be other ways, but upgrading Anaconda seems klike the one with the least liklihood of cross version problems).

Then you install your tensorflow module with

python3 -m pip install tensorflow

Craig Hicks
  • 2,199
  • 20
  • 35
  • OP was on Ubuntu 16.04LTS, using, presumably the latest tensorflow at the time, which was 0.11.0, which ran on py2.7 on linux, as available on Anaconda Cloud https://anaconda.org/conda-forge/tensorflow/files?version=0.11.0 Just FYI, since the particular error the OP was experiencing was a Linux permissions issue. But hopefully this explanation helps ppl understand how pip works a little better – Metagrapher Aug 31 '17 at 07:05
3

If you're only installing things to one user account it is also possible to use pip install --user --upgrade pip avoiding the question of to sudo or not to sudo... just be careful not to use that account with system wide installation of pip goodies.

S0AndS0
  • 860
  • 1
  • 7
  • 20
1

cannot install pip 9 for python3 on ubuntu16 with pip or pip3

solve by: sudo apt-get upgrade python3-pip (here may be run the apt update first.)
pip3 -V pip 9.0.1 from /home/roofe/.local/lib/python3.5/site-packages (python 3.5)


roofe@utnubu:~$ pip install --upgrade pip Collecting pip Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB) 100% |████████████████████████████████| 1.3MB 14kB/s Installing collected packages: pip Successfully installed pip-9.0.1
note: the upper command only successly installed for python2.

roofe@utnubu:~$ pip3 install --upgrade pip3 Collecting pip3 Could not find a version that satisfies the requirement pip3 (from versions: ) No matching distribution found for pip3 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. roofe@utnubu:~$ pip install --upgrade pip3 Collecting pip3 Could not find a version that satisfies the requirement pip3 (from versions: ) No matching distribution found for pip3 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.

LF00
  • 27,015
  • 29
  • 156
  • 295
1

Unsurprisingly none of the answers here worked for me either. What did work was to go to https://pypi.org/project/pip/9.0.3/#files and download the wheel file. Then I ran pip install --user pip-9.0.3-py2.py3-none-any.whl. That successfully got me to 9.0.3.

After that I did pip install --user --upgrade and it successfully upgraded me to 10.0.0. I suppose I could have directly installed 10.0.0 but I also wanted to double check that there wasn't anything else wrong in the chain.

Anyway, here is where you can download the latest pip: https://pypi.org/project/pip/#files

cheshirekow
  • 4,797
  • 6
  • 43
  • 47
1

This is not an actual solution, but the output of the commands above, and who knows, maybe useful for some

To sum up what's going on here. The system is a Raspbian 8 Jessie LITE running on a Raspberry Pi 3 meta B, so in short, it's a Debian based Linux OS just like Ubuntu.

On this system the command pip install --upgrade pip doesn't do the job. My thinking is it just simply can't do it because of the required Debian packages which are installed with the sudo apt-get upgrade python-pip command (about 27MB). Pip just simply not allowed to upgrade Debian packages.

I think the source of difference in results for the self-updating command is a minor version difference which doesn't need system level upgrade can be done like that but every other case will require an actual software upgrade, but I may be wrong. Based on my little investigation the correct solution for Debian Linux is:
sudo apt-get upgrade python-pip
or
sudo apt-get upgrade python3-pip
as others stated before.

    pi@lalaland:~ $ pip show pip
    ---
    Name: pip
    Version: 1.5.6
    Location: /usr/lib/python2.7/dist-packages
    Requires: 

    pi@lalaland:~ $ pip3 show pip
    ---
    Name: pip
    Version: 1.5.6
    Location: /usr/lib/python3/dist-packages
    Requires: 

    pi@lalaland:~ $ sudo pip install --upgrade pip
    Downloading/unpacking pip from https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl#sha256=717cdffb2833be8409433a93746744b59505f42146e8d37de6c62b430e25d6d7
      Downloading pip-10.0.1-py2.py3-none-any.whl (1.3MB): 1.3MB downloaded
    Installing collected packages: pip
      Found existing installation: pip 1.5.6
        Not uninstalling pip at /usr/lib/python2.7/dist-packages, owned by OS
    Successfully installed pip
    Cleaning up...

    pi@lalaland:~ $ pip show pip
    ---
    Name: pip
    Version: 1.5.6
    Location: /usr/lib/python2.7/dist-packages
    Requires: 

    pi@lalaland:~ $ pip3 show pip
    ---
    Name: pip
    Version: 1.5.6
    Location: /usr/lib/python3/dist-packages
    Requires: 

    pi@lalaland:~ $ sudo pip3 install --upgrade pip
    Downloading/unpacking pip from https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl#sha256=717cdffb2833be8409433a93746744b59505f42146e8d37de6c62b430e25d6d7
      Downloading pip-10.0.1-py2.py3-none-any.whl (1.3MB): 1.3MB downloaded
    Installing collected packages: pip
      Found existing installation: pip 1.5.6
        Not uninstalling pip at /usr/lib/python3/dist-packages, owned by OS
    Successfully installed pip
    Cleaning up...

    pi@lalaland:~ $ pip show pip
    ---
    Name: pip
    Version: 1.5.6
    Location: /usr/lib/python2.7/dist-packages
    Requires: 

    pi@lalaland:~ $ pip3 show pip
    ---
    Name: pip
    Version: 1.5.6
    Location: /usr/lib/python3/dist-packages
    Requires: 

    pi@lalaland:~ $ pip -version

    Usage:   
      pip <command> [options]

    no such option: -e

    pi@lalaland:~ $ pip --version
    pip 1.5.6 from /usr/lib/python2.7/dist-packages (python 2.7)

    pi@lalaland:~ $ pip3 --version
    pip 1.5.6 from /usr/lib/python3/dist-packages (python 3.4)

The commands seem to have no effect what so ever.
So time to try to upgrade pip with apt-get.

    pi@lalaland:~ $ sudo apt-get upgrade python-pip
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    Calculating upgrade... python-pip is already the newest version.
    Done
    The following packages have been kept back:
      python-openssl python3-openssl
    The following packages will be upgraded:
      curl git git-core git-man gnupg gnupg-agent gnupg2 gpgv libcurl3 libcurl3-gnutls libicu52 libmad0 libperl5.20 libpoppler46
      libprocps3 libsdl-image1.2 libsnmp-base libsnmp30 libssl1.0.0 libvorbis0a libvorbisenc2 libvorbisfile3 openssl perl perl-base
      perl-modules poppler-utils procps wget xdg-utils
    30 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
    Need to get 27.2 MB of archives.
    After this operation, 731 kB of additional disk space will be used.
    Do you want to continue? [Y/n] y
    Get:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main libperl5.20 armhf 5.20.2-3+deb8u11 [1,348 B]
    :
    Get:30 http://mirrordirector.raspbian.org/raspbian/ jessie/main xdg-utils all 1.1.0~rc1+git20111210-7.4+deb8u1 [65.1 kB]             
    Fetched 27.2 MB in 15s (1,767 kB/s)                                                                                                  
    Reading changelogs... Done
    Preconfiguring packages ...
    :
    Setting up xdg-utils (1.1.0~rc1+git20111210-7.4+deb8u1) ...
    Processing triggers for libc-bin (2.19-18+deb8u10) ...

    pi@lalaland:~ $ pip show pip
    ---
    Name: pip
    Version: 1.5.6
    Location: /usr/lib/python2.7/dist-packages
    Requires: 

    pi@lalaland:~ $ pip3 show pip
    ---
    Name: pip
    Version: 1.5.6
    Location: /usr/lib/python3/dist-packages
    Requires: 

    pi@lalaland:~ $ pip --version
    pip 1.5.6 from /usr/lib/python2.7/dist-packages (python 2.7)

    pi@lalaland:~ $ pip3 --version
    pip 1.5.6 from /usr/lib/python3/dist-packages (python 3.4)

    pi@lalaland:~ $ sudo pip install --upgrade pip
    Requirement already up-to-date: pip in /usr/local/lib/python2.7/dist-packages (10.0.1)

    pi@lalaland:~ $ sudo pip3 install --upgrade pip
    Cache entry deserialization failed, entry ignored
    Requirement already up-to-date: pip in /usr/local/lib/python3.4/dist-packages (10.0.1)

at this point pip --version and pip3 --version still returns wrong version numbers.
Although after a soft-reboot (sudo init 6):

    pi@lalaland:~ $ sudo init 6

    pi@lalaland:~ $ pip show pip
    Name: pip
    Version: 10.0.1
    Summary: The PyPA recommended tool for installing Python packages.
    Home-page: https://pip.pypa.io/
    Author: The pip developers
    Author-email: python-virtualenv@groups.google.com
    License: MIT
    Location: /usr/local/lib/python2.7/dist-packages
    Requires: 
    Required-by: 

    pi@lalaland:~ $ pip3 show pip
    Name: pip
    Version: 10.0.1
    Summary: The PyPA recommended tool for installing Python packages.
    Home-page: https://pip.pypa.io/
    Author: The pip developers
    Author-email: python-virtualenv@groups.google.com
    License: MIT
    Location: /usr/local/lib/python3.4/dist-packages
    Requires: 
    Required-by: 

    pi@lalaland:~ $ pip --version
    pip 10.0.1 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)

    pi@lalaland:~ $ pip3 --version
    pip 10.0.1 from /usr/local/lib/python3.4/dist-packages/pip (python 3.4)

All version numbers are fine.

Gergely M
  • 583
  • 4
  • 11
0

I removed the pip installed by system package manager

sudo apt-get remove python-pip

than I needed to dwonload it from the dist page

cd ~/Downloads
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py

that solved the problem

bendaf
  • 2,981
  • 5
  • 27
  • 62