You are not logged in.

#1 2020-01-04 10:29:25

mb720
Member
Registered: 2020-01-03
Posts: 3

[SOLVED] Broken pip

I'm trying to repair pip after breaking it by accidentally moving /usr/lib/python3.8/site-packages and running sudo python3 -m pip install --user --upgrade pip.

Currently, pip -V produces this:
   

    Traceback (most recent call last):
      File "/usr/bin/pip", line 11, in <module>
        load_entry_point('pip==19.2.3', 'console_scripts', 'pip')()
      File "/usr/lib/python3.8/site-packages/pkg_resources/__init__.py", line 489, in load_entry_point
        return get_distribution(dist).load_entry_point(group, name)
      File "/usr/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2852, in load_entry_point
        return ep.load()
      File "/usr/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2443, in load
        return self.resolve()
      File "/usr/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2449, in resolve
        module = __import__(self.module_name, fromlist=['__name__'], level=0)
      File "/usr/lib/python3.8/site-packages/pip/_internal/__init__.py", line 40, in <module>
        from pip._internal.cli.autocompletion import autocomplete
      File "/usr/lib/python3.8/site-packages/pip/_internal/cli/autocompletion.py", line 8, in <module>
        from pip._internal.cli.main_parser import create_main_parser
      File "/usr/lib/python3.8/site-packages/pip/_internal/cli/main_parser.py", line 11, in <module>
        from pip._internal.commands import (
      File "/usr/lib/python3.8/site-packages/pip/_internal/commands/__init__.py", line 6, in <module>
        from pip._internal.commands.completion import CompletionCommand
      File "/usr/lib/python3.8/site-packages/pip/_internal/commands/completion.py", line 6, in <module>
        from pip._internal.cli.base_command import Command
      File "/usr/lib/python3.8/site-packages/pip/_internal/cli/base_command.py", line 21, in <module>
        from pip._internal.download import PipSession
      File "/usr/lib/python3.8/site-packages/pip/_internal/download.py", line 14, in <module>
        from pip._vendor import requests, urllib3
    ImportError: cannot import name 'requests' from 'pip._vendor' (/usr/lib/python3.8/site-packages/pip/_vendor/__init__.py) 

I have reinstalled requests and other packages like urllib3 using sudo pacman -S urllib3 requests.

After reading this, I tried
   

    sudo rm -rf /usr/lib/python3.8/site-packages/pip /usr/lib/python3.8/site-packages/pkg_resources
    sudo pacman -S python-setuptools python-pip 

but pip would not recover.

I also reinstalled Python using sudo pacman -S python but that didn't help.

In a moment of desperation, I did sudo easy_install pip which I'm pretty sure got me only deeper into trouble.

It seems it's not my entire Python setup that's broken since running python brings up the REPL just fine.

Is there a way to bring Python and pip into a valid state from this?

Please let me know if I can provide anymore information to debug the issue.

Last edited by mb720 (2020-01-05 09:33:51)

Offline

#2 2020-01-04 15:48:42

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 17,040

Re: [SOLVED] Broken pip

What is the output of which -a python
?


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#3 2020-01-04 18:54:03

mb720
Member
Registered: 2020-01-03
Posts: 3

Re: [SOLVED] Broken pip

ewaller wrote:

What is the output of which -a python
?

/usr/bin/python

python -V gives Python 3.8.1

Last edited by mb720 (2020-01-04 18:55:08)

Offline

#4 2020-01-05 02:39:11

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 17,040

Re: [SOLVED] Broken pip

Okay, I was checking that you did not have multiple versions of Python in your path.   So, what happens now when you invoke Python ?

Edit:  Have you reinstalled python-pip using pacman

Last edited by ewaller (2020-01-05 02:48:22)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#5 2020-01-05 04:40:58

eschwartz
Trusted User/Bug Wrangler
Registered: 2014-08-08
Posts: 3,013

Re: [SOLVED] Broken pip

It doesn't matter how many times you install or reinstall packages using pacman. You've broken your system by *trying* to install pip without using pacman. You can recover your system by removing the erroneous files you should not have (which are corrupting your pacman-installed version of pip).

Please install the "lostfiles" package and run the provided "lostfiles" program, which should print out, at a minimum, some files in /usr/lib/python3.8/site-packages/ which are untracked by pacman. Delete anything that doesn't have a good reason to exist outside of pacman (nothing in /usr/lib/python3.8/site-packages/ should ever be installed outside of pacman).

After that, if pip still doesn't work, reinstall it, as well as any other python-* packages which "pacman -Qkk" reports as modified.

In the future, don't ever use sudo pip. If you want to install pip outside of pacman, use it *without* sudo, using the --user flag, so that the worst you can do is mess up $HOME/.local/lib/python3.8/ (in which case you can delete that whole directory and try again).

The Arch Linux developers and the creators of pip are united in this belief: do not use sudo pip to modify the pip (or anything else) installed by your distro package manager.

For extra safety, you may wish to consider using "python -m venv" to create a virtualenv for your own modules, which is entirely for your private use, and unless you use --system-site-packages, it will even install its own copy of pip rather than using the pacman version.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#6 2020-01-05 09:33:15

mb720
Member
Registered: 2020-01-03
Posts: 3

Re: [SOLVED] Broken pip

ewaller wrote:

Okay, I was checking that you did not have multiple versions of Python in your path.   So, what happens now when you invoke Python ?

Edit:  Have you reinstalled python-pip using pacman

Calling python brings up the REPL.
Yes, I've reinstalled python-pip via pacman.


eschwartz wrote:

Please install the "lostfiles" package and run the provided "lostfiles" program, which should print out, at a minimum, some files in /usr/lib/python3.8/site-packages/ which are untracked by pacman.

Thanks for the hint.

Running lostfiles brings up a lot of files including /usr/lib/python3.6/site-packages/ and /usr/lib/python3.7/site-packages/ but nothing from directory /usr/lib/python3.8/.

Now for the good news:

After following your suggestion of running pacman -Qkk, I started reinstalling packages that showed "altered files".

The last command that installed libraries was

sudo pacman -S python-colorama python-chardet python-cffi python-cairo

I'm not sure which of those libraries fixed the original error of

ImportError: cannot import name 'requests' from 'pip._vendor' 

but now, pip -V pleasantly produces

pip 19.2.3 from /usr/lib/python3.8/site-packages/pip (python 3.8)

Before being able to install a package via pip again, in my case using

python3 -m pip install --user --upgrade pynvim

I also had to install python-ordered-set to get rid of the error ModuleNotFoundError: No module named 'ordered_set':

sudo pacman -S python-ordered-set

Thanks for helping me solve this!

eschwartz wrote:

In the future, don't ever use sudo pip.

You bet. :-)
I wish there was a "do you really know what you're doing?" prompt after running this, warning that it will mess up your system.

Last edited by mb720 (2020-01-28 16:23:35)

Offline

#7 2020-01-05 10:01:33

eschwartz
Trusted User/Bug Wrangler
Registered: 2014-08-08
Posts: 3,013

Re: [SOLVED] Broken pip

python-ordered-set is a dependency of python-setuptools, which is in turn a dependency of python-pip, so I don't know why you would be missing it.

At any rate, good to see you were able to fix your issue after my cleanup advice.

mb720 wrote:

I wish there was a "do you really know what you're doing?" prompt after running this, warning that it will mess up your system.

Well, there is discussion about that here: https://github.com/pypa/pip/issues/5605

pip already stopped suggesting the use of sudo pip intall --upgrade pip, if a distro pip is discovered (see https://github.com/pypa/pip/pull/5368).


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#8 2020-01-05 15:28:21

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 17,040

Re: [SOLVED] Broken pip

For the record, you quoted eschwartz twice and attributed me.  It was his advice that cut through this Gordian knot.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#9 2020-02-03 20:08:58

ExecutionByFork
Member
Registered: 2019-03-14
Posts: 9

Re: [SOLVED] Broken pip

Just to put this out there, I just had a similar issue where pip was complaining with

ModuleNotFoundError: No module named 'ordered_set'

When trying to install virtualenvwrapper. I'm not sure what caused it, but installing the missing package with python via

sudo pacman -S python-ordered-set

did fix the error.

Perhaps this is a recent issue in pip? This said though, I did have a dependency management issue not long ago where I couldn't upgrade using pacman due to a chicken and egg problem. I had to uninstall a few packages here and force a few upgrades there to get my system updated, so this likely could have caused the above issue too.

Offline

Board footer

Powered by FluxBB