1

I want to install tensorflow-cpu using pip on my Ubuntu 18.04, 64-bit system and it required pip>=19.0. I was having pip 9.0.x and was using pip3 to install packages but to fulfill the requirement I ran

pip3 install pip

which installed pip 19.2.3 but after doing it I can no longer use pip3. Using pip3 now gives this error

Traceback (most recent call last):
  File "/usr/bin/pip3", line 9, in <module>
    from pip import main
ImportError: cannot import name 'main'

Earlier using pip would give this error

Command 'pip' not found, but can be installed with:

sudo apt install python-pip

but now using it to install packages works totally fine.

I read a lot of articles after which I realised that we use pip for python 2.x and for python 3.x we use pip3. But with the change in behaviour after upgrading pip I'm totally confused and can't find any help. Is using pip to install a package same as installing it using pip3. What are the differences between them?

NikeshPrasad9
  • 51
  • 1
  • 5
  • IIRC if you have both pips installed then you need to use python2 for pip and python3 for pip3. If you do "which python" and then check what version of python is your default based on the path given there you can figure out which version of pip should work for you. I can't recall if this behavior is default or not, but I used to type python2 to make my path use python2 and python3 to make it use python3, before I switched to using conda to determine what version of python I'm using. Using pip and pip3 together can be tricky. – FredMan Sep 29 '19 at 07:45
  • Using pip3 and pip is not the same. Pip3 and pip live in different locations on your hardrive, and install to different locations. see https://stackoverflow.com/questions/29980798/where-does-pip-install-its-packages pip should install to python2.7 version locations and pip3 should install to python3 version locations. – FredMan Sep 29 '19 at 07:53
  • Using 'which python' gives this path '/usr/bin/python'. I installed a package using pip and its location is /home/nik/.local/lib/python3.6/site-packages – NikeshPrasad9 Sep 29 '19 at 08:08
  • If you check the script or executable or whatever it is in /usr/bin/python I suspect it will say it is defaulting to python 3 then, since the installation went to the python3.6 directory. You can also check the default version of python being used by typing python --version If you use the path to python2 and try to use pip it will likely install to the python2 directory instead of python3. EG: path/to/python2/python pip install whatever – FredMan Sep 29 '19 at 08:11
  • It is a shared file at /usr/bin/python and I'm unable to open it. Checking the properties of the file shows "Link Target: python2.7". Checking the version using 'python --version' gives Python 2.7.15+ – NikeshPrasad9 Sep 29 '19 at 08:56

0 Answers0