Skip to content

Laptop Tweaks

Maybe I will keep track of little tweaks I found useful.

Run python3 -m ensurepip


$ python3 -m pip install docker-compose
/home/briecarranza/archivebox/v/bin/python3: No module named pip
(v) briecarranza@lilah:~/archivebox$ which pip
(v) briecarranza@lilah:~/archivebox$ which pip3
$ pip3 install
Traceback (most recent call last):
  File "/home/briecarranza/archivebox/v/bin/pip3", line 5, in <module>
    from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip'
$ pip3 install docker-compose
Traceback (most recent call last):
  File "/home/briecarranza/archivebox/v/bin/pip3", line 5, in <module>
    from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip'
$ apt-cache policy python3-pip
  Installed: 20.3.4-4
  Candidate: 20.3.4-4
  Version table:
 *** 20.3.4-4 500
        500 impish/universe amd64 Packages
        500 impish/universe i386 Packages
        100 /var/lib/dpkg/status


The obligatory SO link

(v) briecarranza@lilah:~/archivebox$ python3 -m ensurepip
Looking in links: /tmp/tmp5mf3ef6h
Processing /tmp/tmp5mf3ef6h/setuptools-44.1.1-py2.py3-none-any.whl
Processing /tmp/tmp5mf3ef6h/pip-20.3.4-py2.py3-none-any.whl
Processing /tmp/tmp5mf3ef6h/pkg_resources-0.0.0-py2.py3-none-any.whl
Installing collected packages: setuptools, pkg-resources, pip
Successfully installed pip-20.3.4 pkg-resources-0.0.0 setuptools-44.1.1
(v) briecarranza@lilah:~/archivebox$ pip3 install docker-compose
Collecting docker-compose
  Using cached docker_compose-1.29.2-py2.py3-none-any.whl (114 kB)
Collecting texttable<2,>=0.9.0
  Using cached texttable-1.6.4-py2.py3-none-any.whl (10 kB)
Collecting python-dotenv<1,>=0.13.0
  Using cached python_dotenv-0.20.0-py3-none-any.whl (17 kB)
Collecting websocket-client<1,>=0.32.0
  Using cached websocket_client-0.59.0-py2.py3-none-any.whl (67 kB)
Collecting dockerpty<1,>=0.4.1
  Using cached dockerpty-0.4.1-py3-none-any.whl
Collecting distro<2,>=1.5.0
  Using cached distro-1.7.0-py3-none-any.whl (20 kB)
Collecting PyYAML<6,>=3.10
  Using cached PyYAML-5.4.1-cp39-cp39-manylinux1_x86_64.whl (630 kB)
^CERROR: Operation cancelled by user

After running python3 -m ensurepip, it works.

A different write-up of the same problem:

I love using virtual environments with Python.

With python3-pip installed, I was running into:

ModuleNotFoundError: No module named 'pip'

Like...which pip worked. But pip install whatever complained that pip couldn't be found. Thanks to this SO, I found that python3 -m ensurepip did the trick.


The documentation for ensurepip says:

The ensurepip package provides support for bootstrapping the pip installer into an existing Python installation or virtual environment. This bootstrapping approach reflects the fact that pip is an independent project with its own release cycle, and the latest available stable version is bundled with maintenance and feature releases of the CPython reference interpreter.

In most cases, end users of Python shouldn’t need to invoke this module directly (as pip should be bootstrapped by default), but it may be needed if installing pip was skipped when installing Python (or when creating a virtual environment) or after explicitly uninstalling pip.