0

I have recently updated my ubuntu version from Ubuntu 18.04 LTS to Ubuntu 20.04 LTS. This process has deleted my older versions of python and now I'm having python3.8 and python2.7 in my machine. However, on using pip for doing anything (even pip --version) gives me the following error:

bash: /home/<user>/.local/bin/pip: /usr/bin/python3.7: bad interpreter: No such file or directory

The same is the issue with pip3. I know that there is no python3.7 in my system now. But I am unable to figure out how to resolve the issue. Here's what I have tried so far:

  1. The first answer in this.

  2. Uninstalling and reinstalling pip.

    sudo apt-get remove python3-pip
    
    sudo apt-get install python3-pip
    
  3.  python3 -m pip --version
    

The above command gives the following error. There are a few of my personal directories also getting used while running this command (which I don't think should happen ideally). Since I not sure about what is the source of the error, I am mentioning the entire message:

Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 184, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.8/runpy.py", line 143, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/usr/lib/python3.8/runpy.py", line 110, in _get_module_details
    __import__(pkg_name)
  File "/home/<user>/Documents/Web dev/SocialSiteClone/socialsite/lib/python3.6/site-packages/pip/__init__.py", line 31, in <module>
    from pip.vcs import git, mercurial, subversion, bazaar  # noqa
  File "/home/<user>/Documents/Web dev/SocialSiteClone/socialsite/lib/python3.6/site-packages/pip/vcs/mercurial.py", line 9, in <module>
    from pip.download import path_to_url
  File "/home/<user>/Documents/Web dev/SocialSiteClone/socialsite/lib/python3.6/site-packages/pip/download.py", line 37, in <module>
    from pip.utils.ui import DownloadProgressBar, DownloadProgressSpinner
  File "/home/<user>/Documents/Web dev/SocialSiteClone/socialsite/lib/python3.6/site-packages/pip/utils/ui.py", line 16, in <module>
    from pip._vendor.progress.helpers import (WritelnMixin,
ModuleNotFoundError: No module named 'pip._vendor.progress.helpers'

Please note that I no longer have python3.6 installed in my system as mentioned before.

However, any of these haven't solved my issue. Could somebody please help in figuring out what to do!

Here is the output of some of the commands which elaborate the specifications of my computer:

  1. Command:

    ls -la /usr/bin/python3.8
    

    Output:

    -rwxr-xr-x 1 root root 5453504 Jul 16 19:30 /usr/bin/python3.8
    
  2. Command:

    echo $PYTHONPATH
    

    Output: (here socialsite is a venv)

    /home/<user>/Documents/Web dev/SocialSiteClone/socialsite/lib/python3.6/site-packages
    
Neuron
  • 5,141
  • 5
  • 38
  • 59
sksingh
  • 27
  • 1
  • 8
  • Does `python3 -m pip ...` works for you? Check `pip` version with `python3 -m pip --version`. – Elyash Oct 06 '20 at 11:34
  • I have actually tried that too and it gives an error in that also. I'll modify the question so that you may have a look at it too! – sksingh Oct 06 '20 at 11:39
  • Please also attach `ls -la /usr/bin/python3.8` output. – Elyash Oct 06 '20 at 11:44
  • Sure will do that! – sksingh Oct 06 '20 at 11:45
  • I think unexpectedly pip command is trying to run python3 from python 2.7 so uninstall python2.7, reboot and try pip again, it should be successful. –  Oct 06 '20 at 11:47
  • 1
    Python3 searches for modules in your `/home//Documents/Web dev/SocialSiteClone/socialsite/lib/python3.6/` directory. Why? Does your `PYTHONPATH` is good? – Elyash Oct 06 '20 at 11:51
  • Are you sure? Because I see in the error message that it's trying to use python3.7! – sksingh Oct 06 '20 at 11:52
  • 1
    See the traceback when you're trying to run `python3 -m pip ...`. Can you add the output of `echo $PYTHONPATH`? – Elyash Oct 06 '20 at 11:56
  • @Elyash could you please tell what should be my PYTHONPATH actually? Currently it is: /home//Documents/Web dev/SocialSiteClone/socialsite/lib/python3.6/site-packages – sksingh Oct 06 '20 at 11:59
  • @Elyansh I have modified the query again, with my PYTHONPATH and also mentioning that socialsite is actually a venv – sksingh Oct 06 '20 at 12:09
  • @Elyash I had probably set the PYTHONPATH to the path mentioned sometime before. I reopened the ~/.bashrc and commented that the line which exports this env var. And now the python3 -m pip ... is working! Thank you very much for your help now at least I am able to run pip with python3 -m. This can be a good answer if you would like to! However the normal pip command still is not working! – sksingh Oct 06 '20 at 12:20
  • I'm glad to hear. About the normal `pip`, can you run `whereis pip`? I think that `pip` is not pointing to Python3's `pip`. – Elyash Oct 06 '20 at 13:28
  • And notice to run `python3 -m pip install virtualenv` again, and `rmvirtualenv ` and rebuild your virtual environment. – Elyash Oct 06 '20 at 13:37
  • Yes, you are right, my pip is not pointing to the right location. However, I actually don't really know how to fix that. I checked it by comparing whereis pip and the output of python -m pip --version. The former one is pointing to some local location which seems to be the issue. Could you please tell on how to fix that or provide some resource where I could read and figure it out. Thank you very much :) – sksingh Oct 07 '20 at 16:29

1 Answers1

1

Notice that it says /home/<user>/.local/bin/pip: .... That indicates that you have a version of pip installed in ~/.local (probably because you installed pip manually at some point), which takes precedence over the system pip. You probably want to get rid of that.

Ture Pålsson
  • 6,088
  • 2
  • 12
  • 15
  • I have uninstalled and reinstalled pip so does that come under manual installation? And what do I need to do to get rid of manual uninstallation and start using system pip instead! Could you please specify? – sksingh Oct 06 '20 at 12:01