19

Docker script docker-compose --version is now throwing a weird error and is complaining about a missing python module ordered_dict. Not sure why is this happening but previously it was working just fine. Not sure if its related but I installed pip for python and later installed awscli using the pip.

Below is the stack trace I get on running docker-compose --version

Traceback (most recent call last):
  File "/usr/bin/docker-compose", line 9, in <module>
    load_entry_point('docker-compose==1.8.0', 'console_scripts', 'docker-compose')()
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 484, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2725, in load_entry_point
    return ep.load()
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2343, in load
    return self.resolve()
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2349, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib/python2.7/dist-packages/compose/cli/main.py", line 14, in <module>
    from . import errors
  File "/usr/lib/python2.7/dist-packages/compose/cli/errors.py", line 9, in <module>
    from docker.errors import APIError
  File "/usr/lib/python2.7/dist-packages/docker/__init__.py", line 20, in <module>
    from .client import Client, AutoVersionClient, from_env # flake8: noqa
  File "/usr/lib/python2.7/dist-packages/docker/client.py", line 18, in <module>
    import requests
  File "/usr/lib/python2.7/dist-packages/requests/__init__.py", line 58, in <module>
    from . import utils
  File "/usr/lib/python2.7/dist-packages/requests/utils.py", line 26, in <module>
    from .compat import parse_http_list as _parse_list_header
  File "/usr/lib/python2.7/dist-packages/requests/compat.py", line 42, in <module>
    from .packages.urllib3.packages.ordered_dict import OrderedDict
ImportError: No module named ordered_dict
htopiwala
  • 620
  • 1
  • 5
  • 16

3 Answers3

32

do it by installing urllib3 version 1.22 and uninstall the previous urllib3 verion by executing the following command in the shell

pip uninstall urllib3
pip install urllib3==1.22
  • It worked for me without specifying the version of urllib for reinstall. You should do the same to have the latest version of this lib. – txemsukr Jan 11 '20 at 16:21
  • For certain OS versions such as Redhat or centos, this can break dependencies at the system level for commands like `yum` so be extra careful about it. – DaiCode-1523 Oct 20 '21 at 01:39
  • Worked for me without specifying version. Thank you ! – Ranjitsinh Dec 20 '21 at 16:29
8

Reinstalling docker-compose did the trick for me. You can reinstall by deleting the docker-compose file from /usr/local/bin and installing it again using instructions provided here.

htopiwala
  • 620
  • 1
  • 5
  • 16
7

You need to re-install.

Below are the steps that worked for me on Ubuntu 18.04

Re-installation steps:

First remove the installed docker-compose binaries:

sudo rm -r /usr/bin/docker-compose
sudo rm -r /usr/local/bin/docker-compose

Installation:

cd ~/

sudo curl -L "https://github.com/docker/compose/releases/download/1.25.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

docker-compose --version

You can read more here: https://docs.docker.com/compose/install/#install-compose

meles
  • 315
  • 1
  • 4
  • 13
user3785966
  • 2,578
  • 26
  • 18