I’ve installed python-pip. It was worked before but suddenly pip throwing error!
I can’t able to make any oparation using pip…
here is the error below
[muhammadabir@muhammadabir-pc ~]$ pip -V
Traceback (most recent call last):
File "/usr/bin/pip", line 5, in <module>
from pip._internal.cli.main import main
File "/usr/lib/python3.10/site-packages/pip/_internal/cli/main.py", line 9, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/usr/lib/python3.10/site-packages/pip/_internal/cli/autocompletion.py", line 10, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/usr/lib/python3.10/site-packages/pip/_internal/cli/main_parser.py", line 8, in <module>
from pip._internal.cli import cmdoptions
File "/usr/lib/python3.10/site-packages/pip/_internal/cli/cmdoptions.py", line 22, in <module>
from pip._vendor.packaging.utils import canonicalize_name
File "/usr/lib/python3.10/site-packages/pip/_vendor/__init__.py", line 61, in <module>
vendored("cachecontrol")
File "/usr/lib/python3.10/site-packages/pip/_vendor/__init__.py", line 33, in vendored
__import__(modulename, globals(), locals(), level=0)
File "/usr/lib/python3.10/site-packages/cachecontrol/__init__.py", line 9, in <module>
from .wrapper import CacheControl
File "/usr/lib/python3.10/site-packages/cachecontrol/wrapper.py", line 1, in <module>
from .adapter import CacheControlAdapter
File "/usr/lib/python3.10/site-packages/cachecontrol/adapter.py", line 5, in <module>
from requests.adapters import HTTPAdapter
File "/home/muhammadabir/.local/lib/python3.10/site-packages/requests/__init__.py", line 63, in <module>
from . import utils
File "/home/muhammadabir/.local/lib/python3.10/site-packages/requests/utils.py", line 27, in <module>
from .cookies import RequestsCookieJar, cookiejar_from_dict
File "/home/muhammadabir/.local/lib/python3.10/site-packages/requests/cookies.py", line 172, in <module>
class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):
AttributeError: module 'collections' has no attribute 'MutableMapping'
[muhammadabir@muhammadabir-pc ~]$
As a rule of thumb for me, if unsure about whether a command needs sudo or not, try the command without sudo first. If it works without sudo, never use sudo for that command,
When you first use the command without sudo, If the command needs sudo it will simply tell you so. No harm, no foul. Then simply run the command with sudo.
Well, no… If a command does not work with sudo that doesn’t mean you should just run it with sudo.
There are certain commands you should never, ever, run with sudo (I call them: sudon't).
For example, a GUI text editor won’t let you edit a root owned file unless you run it with sudo, but you know that you should never do that – never run GUI programs with sudo.
In the case of pip, on Arch Linux (and EndeavourOS) you certainly shouldn’t run it with sudo, ever. Without sudopip won’t let you globally install Python modules, and that’s the whole point – you shouldn’t be doing that. Instead, you should be using pacman (ALPM) to install all global packages, including Python modules. This way, they won’t be invisible to the ALPM.
The same thing is true for npm (for JavaScript) and gem (for Ruby), as well as any other third party package (module) manager. It is safe to use them to install modules locally, but they shouldn’t be used with sudo to install modules globally. On some distros, like Debian and 'Buntu that’s fine, but on Arch, that can cause serious system misbehaviour that can be very difficult to troubleshoot.
TL;DR: don’t use sudo when you shouldn’t be using sudo, even if the command does not work without sudo. Specifically, don’t use sudo with GUI programs and third party package managers like pip, npm, and gem.
That is golden advice Pudge. So obvious, but so easily overlooked. The problem with trying sudo first, is if it works you would not have known if it was going to work without sudo. And, then as Dalto said with sudo…
which you also would not have known about until it came time to update. I fell into this trap once and it became a nightmare updating and fixing anything that was dependent on pip .
No, “first try without sudo, and if that fails, try with sudo” is really bad advice, I’m sorry to say. If you follow it literally, you’ll cause yourself quite a few issues.
I only do this when running a script or app. I do not do this when editing files that have root permissions. For that I only use vi or nano. I guess I wasn’t concise enough.