Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pip is completely malfunctioning after I upgraded to pip version 10. Fix it please! #5495

Closed
VincentCCandela opened this issue Jun 13, 2018 · 12 comments
Labels
auto-locked Outdated issues that have been locked by automation

Comments

@VincentCCandela
Copy link

Pip does not work at all. After running any pip command, I get this:

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

  • Pip version: 10
  • Python version: 2.7.12
  • Operating system: Ubuntu 16.04
@pradyunsg
Copy link
Member

Hey @VincentCCandela!

It seems you've installed a newer version of pip over an existing apt-manages installation on your system. Did you run pip with sudo?

Before you run the following commands, could you provide the output of:

$ python -m pip --version

I think you can work around this by reinstalling the apt-installed version of pip and upgrading the version of pip to be installed in your user-local directory.

Regardless, python -m pip should be working for you.

$ sudo apt install --reinstall python-pip
...
$ pip install --upgrade --user pip

@rankun203
Copy link

$ sudo apt install --reinstall python-pip
...
$ pip install --upgrade --user pip

Outputs

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

@pfmoore
Copy link
Member

pfmoore commented Jun 15, 2018

@pradyunsg I don't know exactly what the Ubuntu /usr/bin/pip script does, but I'm not surprised at the results @rankun203 got. Installing as user would still shadow the system pip, and so from pip import main would still fail.

It sounds like the Ubuntu script is too simplistic and doesn't ensure that it always accesses the system (apt installed) copy of pip.

@rankun203 unless you need to upgrade pip, I'd suggest sticking with the system provided pip (and pushing Ubuntu to provide an updated version installable via apt). If you do need the new features, then you need to install a local copy of pip and run it via the pip wrapper that gets installed when you installed pip. Doing that will involve fixing up your PATH to ensure that it's preferred over the OS-supplied version, of course.

@rankun203
Copy link

rankun203 commented Jun 15, 2018

@pfmoore Thanks for clarification, I ended up using the command from one of above comments:

python -m command args...

And it worked, I'm not familiar with pip, so thank you a lot for answering those questions.

If I need other versions of pip, now I prefer launch a Docker container.

@pfmoore
Copy link
Member

pfmoore commented Jun 15, 2018

My apologies, I should have mentioned, python -m pip command args... is a much more reliable way of running pip (it's relatively commonly used on Windows, and as I'm not a Linux user I tend to forget it's not better known there).

@pradyunsg
Copy link
Member

Installing as user would still shadow the system pip, and so from pip import main would still fail.

Indeed. My bad.

@denised
Copy link

denised commented Jun 21, 2018

I think I am seeing a similar issue, on a CentOS Docker container which failed to build.
Walking through the Dockerfile steps manually, I found this:

yum install -y python36 ==> installs /usr/bin/python36 and /usr/bin/pip-3.6
pip-3.6 install --update pip ==> installs /usr/local/bin/pip and breaks /usr/bin/pip-3.6

After the update, running /usr/bin/pip-3.6 --version produces the following error:

pkg_resources.DistributionNotFound: The 'pip==9.0.3' distribution was not found and is required by the application

Looking at the contents of /usr/bin/pip-3.6, it is pretty obvious why it fails:

#!/usr/bin/python3.6
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==9.0.3','console_scripts','pip3.6'
__requires__ = 'pip==9.0.3'
import re
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(
        load_entry_point('pip==9.0.3', 'console_scripts', 'pip3.6')()
    )

What isn't clear to me is how this ever could have worked? Who generates the /usr/bin/pip-3.6 executable script? Is this a yum issue not a python/pip issue?

@pradyunsg pradyunsg added the S: needs triage Issues/PRs that need to be triaged label Jul 23, 2018
@JReming85
Copy link

JReming85 commented Oct 15, 2018

pip is installing the updated pip in /usr/local/bin, and since you installed pip from the package manager its located in /usr/bin

you need to mv the updated pip /usr/local/bin/pip to /usr/bin/pip

This should work perfectly fine

Version 2.* to 3.*
sudo cp /usr/local/bin/pip* /usr/bin/

Version 2.*
sudo cp /usr/local/bin/pip /usr/bin/ && sudo cp /usr/local/bin/pip2* /usr/bin/

Version 3.*
sudo cp /usr/local/bin/pip /usr/bin/ && sudo cp /usr/local/bin/pip3* /usr/bin/

@denised
Copy link

denised commented Nov 1, 2018

@JReming85 --- That's a good workaround, but I do think the issue should be addressed in the package itself. Something as fundamental as "updating pip" should just work.

@JReming85
Copy link

If you were to compile/build your own version of pip it would work 100%, however since you are using a prebuilt version from the repository, its installing per the default self compiled location.

Since you did not create the original package, maybe you should try using --install-options , --root or --target to tell it what bin you want to install in.

@pradyunsg
Copy link
Member

Closing this issue in favor of #5599.

@lock
Copy link

lock bot commented May 31, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label May 31, 2019
@triage-new-issues triage-new-issues bot removed the S: needs triage Issues/PRs that need to be triaged label May 31, 2019
@lock lock bot locked as resolved and limited conversation to collaborators May 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation
Projects
None yet
Development

No branches or pull requests

6 participants