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

  Installed: 3.5.1-1
  Candidate: 3.5.1-1
  Version table:
 *** 3.5.1-1 0
        100 /var/lib/dpkg/status
  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

  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

  • 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 Feb 15 '16 at 8:04
  • 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. – Byte Commander Feb 15 '16 at 8:28
  • 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 <ftpmaster@ubuntu.com> 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 – Ritesh Shakya Feb 15 '16 at 8:32
  • 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 Feb 15 '16 at 8:44
  • 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. – Byte Commander Feb 15 '16 at 9:16

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

The basic steps are:

sudo apt-get update

Now that the package lists have been updated we can upgrade to the latest versions with the apt-get upgrade command:

sudo apt-get -y upgrade

Once the packages have been upgraded, we can install Python 3.7. This is done with the apt-get install command:

sudo apt-get install -y python3.7

Once the installation is complete, we confirm that it was successful by calling Python 3.7 and printing out the version number:

python3.7 -V

# expected output
Python 3.7.3

Now we have successfully completed the installation of Python. Since we want to work with other Python packages in the future, we can now install the package management program PIP. For this we execute the following command:

sudo apt-get install -y python3-pip

In the following, we make sure that Python 3.7 is the latest python3 version. To achieve that we set a symbolic link to python3.

sudo ln -sf /usr/bin/python3.7 /usr/bin/python3

Once PIP has been installed we have to update PIP. Unfortunately we have to do this manually although we have just installed PIP, cause the installed version is pretty old, so yes, this step is necessary:

python3 -m pip install --upgrade pip

Once the installation is complete we also confirm this by calling the version number of PIP:

python3 -m pip -V

# expected output
pip 19.2.1 from /home/vagrant/.local/lib/python3.7/site-packages/pip (python 3.7)

Now we are still testing if we can actually install libraries with PIP. For this we use a very popular Python math library named numpy

python3 -m pip install numpy

For the full video and text source go here:
Video Source
Text Source

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.