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
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
$ 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
@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.
@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.
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).
Installing as user would still shadow the system pip, and so from pip import main would still fail.
Indeed. My bad.
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:
````
__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?
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/
@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.
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.
Closing this issue in favor of #5599.
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.
Most helpful comment
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/