aboutsummaryrefslogtreecommitdiff
path: root/content/weblog/2018-08-03_how-to-break-and-repair-pip/index.md
blob: c2aa000c6f2099fc99e79685f61bb495c8eb68e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
+++
title = "How to break pip, and how to repair it..."
date = 2018-08-03T22:00:00Z
+++

Sometimes a program may suggest to you something, and you may following said
program's suggestion, because, why not, you trust the devs because they've done
an amazing job developing the program, and heck, they should know what they are
doing with their tools.

<!-- more -->

With pip, this does not seem to be the case however. I've come across this
issue on my laptop and desktop computers running Manjaro, and while fixed it on
my laptop, I forgot how to fix it by the time I encountered on my desktop. The
problem: pip refuses to collect a package while trying to install any package
system wide (e.g. pywal), exiting with an exception like 'ModuleNotFoundError'
or something similar.

First, I'll write down what NOT to do to avoid getting this error.

You may get a message like this when after installing a package with pip

```sh
You are using pip version x.x.x, however version x.x is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
```

If you get the following while NOT using a virtual environment, don't pay
attention to it. Don't even look at it. Just ignore it. I didn't, and now I am
writing a post about how to fix the mess that it causes because of following
that seemingly innocent and well-intended advice. At least not if you are using
an Arch-based distribution, don't really know about how this is managed in
other distributions, since I don't recall having this problem when using
Debian.

Now, if you are using a virtual environment, you obviously can and should
upgrade pip this way. However, system-wide, your package manager (pacman)
should take care of upgrading pip along with your other packages when you
upgrade your system (pacman -Syu).

## The fix

If you unfortunately, like me, already ran the upgrade through pip, you should
first delete some files, by running this command:

```sh
$ sudo rm -rf /usr/lib/python3.6/site-packages/pip /usr/lib/python3.6/site-packages/pkg_resources
```

Then, you should reinstall pip and setup tools:

```sh
$ sudo pacman -S python-setuptools python-pip
```

And that's it! Your pip should now be as good as new.

I found the solution in this forum thread: [https://bbs.archlinux.org/viewtopic.php?id=237451](https://bbs.archlinux.org/viewtopic.php?id=237451)