ImportError: No module named ordered_dict

Whenever i tried to install pip3 in yunhost server, it keep giving me this error.i require this package for aws cli and its endpoint plugin. I didnt understand this error so can someone help me with this

The following NEW packages will be installed:
  python3-pip
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
1 not fully installed or removed.
Need to get 0 B/142 kB of archives.
After this operation, 599 kB of additional disk space will be used.
Setting up yunohost (3.7.1.3) ...
Regenerating configuration, this might take a while...
Success! Configuration updated for 'dnsmasq'
Launching migrations..
Traceback (most recent call last):
  File "/usr/lib/moulinette/yunohost/tools.py", line 1255, in _load_migration
    module = import_module("yunohost.data_migrations.{}".format(migration_id))
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/usr/lib/moulinette/yunohost/data_migrations/0002_migrate_to_tsig_sha256.py", line 3, in <module>
    import requests
  File "/usr/lib/python2.7/dist-packages/requests/__init__.py", line 63, in <module>
    from . import utils
  File "/usr/lib/python2.7/dist-packages/requests/utils.py", line 24, in <module>
    from ._internal_utils import to_native_string
  File "/usr/lib/python2.7/dist-packages/requests/_internal_utils.py", line 11, in <module>
    from .compat import is_py2, builtin_str, str
  File "/usr/lib/python2.7/dist-packages/requests/compat.py", line 46, in <module>
    from .packages.urllib3.packages.ordered_dict import OrderedDict
ImportError: No module named ordered_dict
Error: Could not load migration 0002_migrate_to_tsig_sha256: No module named ordered_dict
dpkg: error processing package yunohost (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 yunohost
E: Sub-process /usr/bin/dpkg returned an error code (1)

Well it apparently has nothing to do with pip3 and it sounds more like a general issue with your server

I don’t even understand how it can happen but maybe try to

apt install --reinstall python-requests python-urllib3
1 Like
Preparing to unpack .../python-requests_2.12.4-1_all.deb ...
Unpacking python-requests (2.12.4-1) over (2.12.4-1) ...
Preparing to unpack .../python-urllib3_1.19.1-1_all.deb ...
Unpacking python-urllib3 (1.19.1-1) over (1.19.1-1) ...
Setting up python-urllib3 (1.19.1-1) ...
Setting up python-requests (2.12.4-1) ...
Setting up yunohost (3.7.1.3) ...
Regenerating configuration, this might take a while...
Success! Configuration updated for 'dnsmasq'
Launching migrations..
Traceback (most recent call last):
  File "/usr/lib/moulinette/yunohost/tools.py", line 1255, in _load_migration
    module = import_module("yunohost.data_migrations.{}".format(migration_id))
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/usr/lib/moulinette/yunohost/data_migrations/0002_migrate_to_tsig_sha256.py", line 3, in <module>
    import requests
  File "/usr/lib/python2.7/dist-packages/requests/__init__.py", line 63, in <module>
    from . import utils
  File "/usr/lib/python2.7/dist-packages/requests/utils.py", line 24, in <module>
    from ._internal_utils import to_native_string
  File "/usr/lib/python2.7/dist-packages/requests/_internal_utils.py", line 11, in <module>
    from .compat import is_py2, builtin_str, str
  File "/usr/lib/python2.7/dist-packages/requests/compat.py", line 46, in <module>
    from .packages.urllib3.packages.ordered_dict import OrderedDict
ImportError: No module named ordered_dict
Error: Could not load migration 0002_migrate_to_tsig_sha256: No module named ordered_dict
dpkg: error processing package yunohost (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 yunohost
E: Sub-process /usr/bin/dpkg returned an error code (1)

No luck with that either

Even when i just updating the package i get few error as well

Success! Configuration updated for 'dnsmasq'
Launching migrations..
Traceback (most recent call last):
  File "/usr/lib/moulinette/yunohost/tools.py", line 1255, in _load_migration
    module = import_module("yunohost.data_migrations.{}".format(migration_id))
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/usr/lib/moulinette/yunohost/data_migrations/0002_migrate_to_tsig_sha256.py", line 3, in <module>
    import requests
  File "/usr/lib/python2.7/dist-packages/requests/__init__.py", line 63, in <module>
    from . import utils
  File "/usr/lib/python2.7/dist-packages/requests/utils.py", line 24, in <module>
    from ._internal_utils import to_native_string
  File "/usr/lib/python2.7/dist-packages/requests/_internal_utils.py", line 11, in <module>
    from .compat import is_py2, builtin_str, str
  File "/usr/lib/python2.7/dist-packages/requests/compat.py", line 46, in <module>
    from .packages.urllib3.packages.ordered_dict import OrderedDict
ImportError: No module named ordered_dict
Error: Could not load migration 0002_migrate_to_tsig_sha256: No module named ordered_dict
dpkg: error processing package yunohost (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
E: Sub-process /usr/bin/dpkg returned an error code (1)

Can you confirm that you reproduce the issue if you just run :

python -c "import requests;"

Anyway it looks like there’s definitely something funky with your installation of python-requests

I would try to check the output of dpkg --list | grep python-requests

$ dpkg --list | grep python-requests
ii  python-requests                       2.12.4-1 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/requests/__init__.py", line 63, in <module>
    from . import utils
  File "/usr/lib/python2.7/dist-packages/requests/utils.py", line 24, in <module>
    from ._internal_utils import to_native_string
  File "/usr/lib/python2.7/dist-packages/requests/_internal_utils.py", line 11, in <module>
    from .compat import is_py2, builtin_str, str
  File "/usr/lib/python2.7/dist-packages/requests/compat.py", line 46, in <module>
    from .packages.urllib3.packages.ordered_dict import OrderedDict
ImportError: No module named ordered_dict

And so dpkg --list | grep python-requests

ii python-requests 2.12.4-1
d simple HTTP library for Python2, built for human beings

everything was fine, it starts to happen when i installed aws cli and the error pop up during installation.
so i was just looking around to fix it, i think by mistake when cmd pip3 to install endpoint plugin doesnt work i also installed python 3 as well, which could be the reason behind this error.

just guessing not really sure though

pip3 install awscli-plugin-endpoint

Python

What about

dpkg --verify python-requests

(the command should return nothing)

Yeah it return nothing

Weeeeelll …

what about

python -c "import urllib3.packages.ordered_dict;"
dpkg --list | grep python-urllib3

and

dpkg --verify python-urllib3
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named ordered_dict

ii python-urllib3 1.19.1-1 all HTTP library with thread-safe connection pooling for Python

Returns nothing

So if you run

/usr/lib/python2.7/dist-packages/urllib3/packages/

there’s no ordered_dict.py ?

What about dpkg -L python-urllib3 | grep "/packages/" | grep "py$"

there’s no ordered_dict.py ?

There is

/usr/lib/python2.7/dist-packages/urllib3/packages/__init__.py
/usr/lib/python2.7/dist-packages/urllib3/packages/backports/__init__.py
/usr/lib/python2.7/dist-packages/urllib3/packages/backports/makefile.py
/usr/lib/python2.7/dist-packages/urllib3/packages/ordered_dict.py
/usr/lib/python2.7/dist-packages/urllib3/packages/ssl_match_hostname/__init__.py
/usr/lib/python2.7/dist-packages/urllib3/packages/ssl_match_hostname/_implementation.py

Djeez what’s going on …

Can you try

python -c "import sys; print(sys.path)"

and

python -c "import urllib3; print(urllib3)"

im also clueless if you wanna look into server i can provide you access

['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages']

<module ‘urllib3’ from ‘/usr/local/lib/python2.7/dist-packages/urllib3/init.pyc’>

That’s it : that one is loaded from /usr/local, probably meaning it got installed globally by pip.

So looks like the version of urllib3 installed is inconsistent with the version of requests…

My guess is that it can be fixed by running pip2 install requests

But ultimately it sounds like it has nothing to do with Yunohost or Pip3 …

Bump ? Did it fix the issue ? :confused: