Trying to Install Pip using python-pip

6,714

Your apt-cache policy python output told me that you could not install the correct python version (2.7.x) from the repositories. As Python is located in the main repository, we should first try to activate that repository (again) and update the package lists:

sudo add-apt-repository main
sudo apt-get update

As you got an invalid signature (BADSIG) error, we completely remove all package lists and re-download them. Also in case the error prevented it from working, we try to enable the main repository again.

sudo rm -rf /var/lib/apt/lists/*
sudo add-apt-repository main
sudo apt-get update

Now the new apt-cache policy python output shows the correct version available from the server, so we can now force the downgrade of our package python to the required version:

sudo apt-get install python=2.7.5-5ubuntu3

We then need to clean the locally cached wrong 3.5 version and just empty the entire package cache therefore:

sudo apt-get clean

Then we let it try to upgrade all remaining packages and hope for the best:

sudo apt-get upgrade
Share:
6,714

Related videos on Youtube

Ritesh Shakya
Author by

Ritesh Shakya

Profession Wise:- Work at Deerwalk Inc as a Java Developer working with hadoop and Cascading Currently Learning: Python and Mobile Game Development. Interested In: Deep Learning, Cyber Securty For Fun : Play a lot of MOBA games :D

Updated on September 18, 2022

Comments

  • Ritesh Shakya
    Ritesh Shakya almost 2 years

    Was trying to install Pip through the command

    I was getting the following error message.

    You might want to run 'apt-get -f install' to correct these:
    The following packages have unmet dependencies:
    .....
    E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
    

    Also as stated in the terminal tried using the command

    sudo apt-get -f install
    

    Which gave this in return

    Correcting dependencies... failed.
    The following packages have unmet dependencies:
    .....
    E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.
    E: Unable to correct dependencies
    

    As Suggested in some threads I tried using sudo apt-get install --fix-broken && sudo apt-get autoremove && sudo apt-get update && sudo apt-get install samba but didnt work. I also tried removing the individual package but this failed as well. I have both python 2.7 as well 3.5.1 installed.

    My python -V returns Python 2.7.6.

    My python3 -V returns Python 3.5.1.

    My apt-cache policy python python3 returns

    python:
      Installed: 3.5.1-1
      Candidate: 3.5.1-1
      Version table:
     *** 3.5.1-1 0
            100 /var/lib/dpkg/status
    python3:
      Installed: 3.4.0-0ubuntu2
      Candidate: 3.4.0-0ubuntu2
      Version table:
     *** 3.4.0-0ubuntu2 0
            100 /var/lib/dpkg/status
    

    After using sudo rm -rf /var/lib/apt/lists/* ; sudo apt-get update ; sudo add-apt-repository main; apt-cache policy python

    python:
      Installed: 3.5.1-1
      Candidate: 3.5.1-1
      Version table:
     *** 3.5.1-1 0
            100 /var/lib/dpkg/status
         2.7.5-5ubuntu3 0
            500 http://archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages
    

    Thanks in advance

    • Byte Commander
      Byte Commander over 8 years
      Please show me the output of python -V ; python3 -V ; apt-cache policy python python3. Make sure you edit your question to provide it, because comments don't preserve formatting. Thanks!
    • Byte Commander
      Byte Commander over 8 years
      This is strange, did you modify the output of apt-cache policy python and remove some lines? Please run sudo add-apt-repository main && sudo apt-get update && apt-cache policy python and add the output to your question again. The package python must provide a Python version 2.7, not 3.5. I wonder why you don't see any installation candidates except the cached one.
    • Ritesh Shakya
      Ritesh Shakya over 8 years
      I didnt do anything to modify the code. The command you mentioned returned hive.ubuntu.com trusty Release: The following signatures were invalid: BADSIG 16126D3A3E5C1192 Ubuntu Extras Archive Automatic Signing Key <[email protected]> W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/Release W: Some index files failed to download. They have been ignored, or old ones used instead. python: Installed: 3.5.1-1 Candidate: 3.5.1-1 Version table: *** 3.5.1-1 0 100 /var/lib/dpkg/status
    • Byte Commander
      Byte Commander over 8 years
      Please run sudo rm -rf /var/lib/apt/lists/* ; sudo apt-get update ; sudo add-apt-repository main. Any errors? What output does apt-cache policy python give you now? (And still: edit your question. Comments have ugly formatting)
    • Byte Commander
      Byte Commander over 8 years
      Okay, that looks good. Now you can downgrade the python package to the required 2.7.5-5 using sudo apt-get install python=2.7.5-5ubuntu3. Please run that and sudo apt-get clean and sudo apt-get upgrade and finally try your original commands again afterwards. Tell me if it worked and I'll convert these comments into an answer.
    • Ritesh Shakya
      Ritesh Shakya over 8 years
      Sorry I ended up crashing the office machine. Couldn't reply from there. apt-get -f install removed all dependent packages and computer refused to start.
    • Byte Commander
      Byte Commander over 8 years
      Can you upload the content of you file /var/log/apt/history.log to e.g. pastebin.com and give me the link? That way we can find out which packages exactly got removed and reinstall them manually in the correct version.
    • Ritesh Shakya
      Ritesh Shakya over 8 years
      Currently I'm at home will do so as soon as I reach office tomorrow.. Thanks a million
    • Byte Commander
      Byte Commander over 8 years
      What might also help to recover your packages is this question: askubuntu.com/q/249367/367990
    • Ritesh Shakya
      Ritesh Shakya over 8 years
      Hello here is the pastebin link you requested [pastebin.com/kWaZkUGN]
    • Ritesh Shakya
      Ritesh Shakya over 8 years
      Kinda got back the important packages using apt-get install --reinstall gdm; dpkg-reconfigure gdm; apt-get install --reinstall gnome; now tring to reinstall additional packages. Also the pip issue has been solved thanks a ton. how do i flag as resolved
    • Byte Commander
      Byte Commander over 8 years
      As you managed to resolve the uninstalled packages yourself, I don't really need the pastebin any more. But to mark a question as solved, you accept an answer by clicking the grey tick symbol on the left of it. I've converted my comments into an answer for you. Oh, and make sure you have read our little tour page to learn the most important things about how this site works. Thanks!