Search code examples
pythoncryptographyvirtualenvparamikosix

Import issue with Python six library


inside my virtualenv I have a lot of libraries that use six as dependency but paramiko and python-keystoneclient raise this import error:

ERROR:paramiko.transport:Unknown exception: cannot import name urllib_parse
ERROR:paramiko.transport:Traceback (most recent call last):
ERROR:paramiko.transport:  File "/.../lib/python2.7/site-packages/paramiko/transport.py", line 1772, in run
ERROR:paramiko.transport:    self.kex_engine.parse_next(ptype, m)
ERROR:paramiko.transport:  File "/.../lib/python2.7/site-packages/paramiko/kex_group1.py", line 75, in parse_next
ERROR:paramiko.transport:    return self._parse_kexdh_reply(m)
ERROR:paramiko.transport:  File "/.../lib/python2.7/site-packages/paramiko/kex_group1.py", line 111, in _parse_kexdh_reply
ERROR:paramiko.transport:    self.transport._verify_key(host_key, sig)
ERROR:paramiko.transport:  File "/.../lib/python2.7/site-packages/paramiko/transport.py", line 1617, in _verify_key
ERROR:paramiko.transport:    key = self._key_info[self.host_key_type](Message(host_key))
ERROR:paramiko.transport:  File "/.../lib/python2.7/site-packages/paramiko/rsakey.py", line 58, in __init__
ERROR:paramiko.transport:    ).public_key(default_backend())
ERROR:paramiko.transport:  File "/.../lib/python2.7/site-packages/cryptography/hazmat/backends/__init__.py", line 35, in default_backend
ERROR:paramiko.transport:    _default_backend = MultiBackend(_available_backends())
ERROR:paramiko.transport:  File "/.../lib/python2.7/site-packages/cryptography/hazmat/backends/__init__.py", line 22, in _available_backends
ERROR:paramiko.transport:    "cryptography.backends"
ERROR:paramiko.transport:  File "/.../lib/python2.7/site-packages/pkg_resources/__init__.py", line 2235, in resolve
ERROR:paramiko.transport:    module = __import__(self.module_name, fromlist=['__name__'], level=0)
ERROR:paramiko.transport:  File "/.../lib/python2.7/site-packages/cryptography/hazmat/backends/openssl/__init__.py", line 7, in <module>
ERROR:paramiko.transport:    from cryptography.hazmat.backends.openssl.backend import backend
ERROR:paramiko.transport:  File "/.../lib/python2.7/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 15, in <module>
ERROR:paramiko.transport:    from cryptography import utils, x509
ERROR:paramiko.transport:  File "/.../lib/python2.7/site-packages/cryptography/x509/__init__.py", line 7, in <module>
ERROR:paramiko.transport:    from cryptography.x509.base import (
ERROR:paramiko.transport:  File "/.../lib/python2.7/site-packages/cryptography/x509/base.py", line 15, in <module>
ERROR:paramiko.transport:    from cryptography.x509.extensions import Extension, ExtensionType
ERROR:paramiko.transport:  File "/.../lib/python2.7/site-packages/cryptography/x509/extensions.py", line 22, in <module>
ERROR:paramiko.transport:    from cryptography.x509.general_name import GeneralName, IPAddress, OtherName
ERROR:paramiko.transport:  File "/.../lib/python2.7/site-packages/cryptography/x509/general_name.py", line 15, in <module>
ERROR:paramiko.transport:    from six.moves import urllib_parse
ERROR:paramiko.transport:ImportError: cannot import name urllib_parse

I went through internet to find a way to fix this problem without solving it.

I already tried these steps:

  • re-install any libraries involved
  • re-install the virtualenv
  • tried with several older six versions

These are the versions of libraries:

  • cryptography==1.4
  • keystoneauth1==2.8.0
  • paramiko==2.0.1
  • python-keystoneclient==3.1.0
  • python-swiftclient==3.0.0
  • six==1.10.0
  • urllib3==1.16

and I got the same issue with these Python versions:

  • Python 2.7.11+ --> Ubuntu 16.04
  • Python 2.7.10 --> Ubuntu 15.10

If I try

from six.moves import urllib_parse

inside a Python shell, it works correctly.

Do you have any idea? Thanks in advance!


Solution

  • Try to downgrade paramiko to 1.16.0. It was a solution in my case. Good luck!