1

After upgrading pip, I try to do a 'pip freeze', but i've this error :

# pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl (1.3MB)
    100% |################################| 1.3MB 737kB/s
Installing collected packages: pip
  Found existing installation: pip 9.0.1
    Uninstalling pip-9.0.1:
      Successfully uninstalled pip-9.0.1
Successfully installed pip-10.0.1

# pip freeze
Traceback (most recent call last):
  File "/usr/local/bin/pip", line 7, in <module>
    from pip._internal import main
  File "/usr/local/lib/python2.7/dist-packages/pip/_internal/__init__.py", line 42, in <module>
    from pip._internal import cmdoptions
  File "/usr/local/lib/python2.7/dist-packages/pip/_internal/cmdoptions.py", line 16, in <module>
    from pip._internal.index import (
  File "/usr/local/lib/python2.7/dist-packages/pip/_internal/index.py", line 15, in <module>
    from pip._vendor import html5lib, requests, six
  File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/__init__.py", line 86, in <module>
    from pip._vendor.urllib3.contrib import pyopenssl
  File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/urllib3/contrib/pyopenssl.py", line 46, in <module>
    import OpenSSL.SSL
  File "/usr/lib/python2.7/dist-packages/OpenSSL/__init__.py", line 8, in <module>
    from OpenSSL import rand, crypto, SSL
  File "/usr/lib/python2.7/dist-packages/OpenSSL/SSL.py", line 105, in <module>
    SSL_ST_INIT = _lib.SSL_ST_INIT
AttributeError: 'module' object has no attribute 'SSL_ST_INIT'

Reading some post here, I found various solutions, but it's not working. So I try another things, like installing using easy_install :

# sudo python -m easy_install --upgrade pyOpenSSL
Searching for pyOpenSSL
Reading https://pypi.python.org/simple/pyOpenSSL/
Best match: pyOpenSSL 18.0.0
Downloading https://files.pythonhosted.org/packages/9b/7c/ee600b2a9304d260d96044ab5c5e57aa489755b92bbeb4c0803f9504f480/pyOpenSSL-18.0.0.tar.gz#sha256=6488f1423b00f73b7ad5167885312bb0ce410d3312eb212393795b53c8caa580
Processing pyOpenSSL-18.0.0.tar.gz
Writing /tmp/easy_install-_qJ8_t/pyOpenSSL-18.0.0/setup.cfg
Running pyOpenSSL-18.0.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-_qJ8_t/pyOpenSSL-18.0.0/egg-dist-tmp-KM4cDC
warning: no previously-included files found matching 'leakcheck'
warning: no previously-included files found matching 'codecov.yml'
warning: no previously-included files matching '*.py' found under directory 'leakcheck'
warning: no previously-included files matching '*.pem' found under directory 'leakcheck'
warning: no previously-included files matching '*.cert' found under directory 'examples/simple'
warning: no previously-included files matching '*.pkey' found under directory 'examples/simple'
no previously-included directories found matching 'doc/_build'
no previously-included directories found matching '.travis'
no previously-included directories found matching '.mention-bot'
zip_safe flag not set; analyzing archive contents...
Adding pyOpenSSL 18.0.0 to easy-install.pth file

Installed /usr/local/lib/python2.7/dist-packages/pyOpenSSL-18.0.0-py2.7.egg
Processing dependencies for pyOpenSSL
Searching for cryptography>=2.2.1
Reading https://pypi.python.org/simple/cryptography/
Best match: cryptography 2.2.2
Downloading https://files.pythonhosted.org/packages/ec/b2/faa78c1ab928d2b2c634c8b41ff1181f0abdd9adf9193211bd606ffa57e2/cryptography-2.2.2.tar.gz#sha256=9fc295bf69130a342e7a19a39d7bbeb15c0bcaabc7382ec33ef3b2b7d18d2f63
Processing cryptography-2.2.2.tar.gz
Writing /tmp/easy_install-rHRU6X/cryptography-2.2.2/setup.cfg
Running cryptography-2.2.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-rHRU6X/cryptography-2.2.2/egg-dist-tmp-eABQpn
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/lib/python2.7/dist-packages/easy_install.py", line 5, in <module>
    main()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 2199, in main
    lambda: setup(
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 2185, in with_ei_usage
    return f()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 2202, in <lambda>
    distclass=DistributionWithoutHelpCommands, **kw
  File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 393, in run
    self.easy_install(spec, not self.no_deps)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 636, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 668, in install_item
    self.process_distribution(spec, dist, deps)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 716, in process_distribution
    [requirement], self.local_index, self.easy_install
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 631, in resolve
    dist = best[req.key] = env.best_match(req, ws, installer)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 874, in best_match
    return self.obtain(req, installer)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 886, in obtain
    return installer(requirement)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 636, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 666, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 856, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 1078, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 1063, in run_setup
    run_setup(setup_script, args)
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 68, in run_setup
    DirectorySandbox(setup_dir).run(runner)
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 114, in run
    return func()
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 67, in runner
    _execfile(setup_script, ns)
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 43, in _execfile
    exec(code, globals, locals)
  File "/tmp/easy_install-rHRU6X/cryptography-2.2.2/setup.py", line 28, in <module>
RuntimeError: cryptography requires setuptools 18.5 or newer, please upgrade to a newer version of setuptools

and, so, upgrading 'setuptools' :

# sudo python -m easy_install --upgrade setuptools
Searching for setuptools
Reading https://pypi.python.org/simple/setuptools/
Best match: setuptools 39.2.0
Downloading https://files.pythonhosted.org/packages/1a/04/d6f1159feaccdfc508517dba1929eb93a2854de729fa68da9d5c6b48fa00/setuptools-39.2.0.zip#sha256=f7cddbb5f5c640311eb00eab6e849f7701fa70bf6a183fc8a2c33dd1d1672fb2
Processing setuptools-39.2.0.zip
Writing /tmp/easy_install-wH5_qA/setuptools-39.2.0/setup.cfg
Running setuptools-39.2.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-wH5_qA/setuptools-39.2.0/egg-dist-tmp-cpMLIT
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'long_description_content_type'
  warnings.warn(msg)
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'project_urls'
  warnings.warn(msg)
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/lib/python2.7/dist-packages/easy_install.py", line 5, in <module>
    main()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 2199, in main
    lambda: setup(
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 2185, in with_ei_usage
    return f()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 2202, in <lambda>
    distclass=DistributionWithoutHelpCommands, **kw
  File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 393, in run
    self.easy_install(spec, not self.no_deps)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 636, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 666, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 856, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 1078, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 1063, in run_setup
    run_setup(setup_script, args)
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 68, in run_setup
    DirectorySandbox(setup_dir).run(runner)
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 114, in run
    return func()
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 67, in runner
    _execfile(setup_script, ns)
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 43, in _execfile
    exec(code, globals, locals)
  File "/tmp/easy_install-wH5_qA/setuptools-39.2.0/setup.py", line 195, in <module>
  File "/usr/lib/python2.7/distutils/core.py", line 111, in setup
    _setup_distribution = dist = klass(attrs)
  File "/usr/lib/python2.7/dist-packages/setuptools/dist.py", line 266, in __init__
    _Distribution.__init__(self,attrs)
  File "/usr/lib/python2.7/distutils/dist.py", line 287, in __init__
    self.finalize_options()
  File "/usr/lib/python2.7/dist-packages/setuptools/dist.py", line 301, in finalize_options
    ep.load()(self, ep.name, value)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2195, in load
    raise ImportError("%r has no %r attribute" % (entry, attr))
ImportError: <module 'setuptools.dist' from '/usr/lib/python2.7/dist-packages/setuptools/dist.pyc'> has no 'check_specifier' attribute

And, the last try, using a specific version of pyOpenSSL :

# sudo pip install pyOpenSSL==16.2.0
Traceback (most recent call last):
  File "/usr/local/bin/pip", line 7, in <module>
    from pip._internal import main
  File "/usr/local/lib/python2.7/dist-packages/pip/_internal/__init__.py", line 42, in <module>
    from pip._internal import cmdoptions
  File "/usr/local/lib/python2.7/dist-packages/pip/_internal/cmdoptions.py", line 16, in <module>
    from pip._internal.index import (
  File "/usr/local/lib/python2.7/dist-packages/pip/_internal/index.py", line 15, in <module>
    from pip._vendor import html5lib, requests, six
  File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/__init__.py", line 86, in <module>
    from pip._vendor.urllib3.contrib import pyopenssl
  File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/urllib3/contrib/pyopenssl.py", line 46, in <module>
    import OpenSSL.SSL
  File "/usr/lib/python2.7/dist-packages/OpenSSL/__init__.py", line 8, in <module>
    from OpenSSL import rand, crypto, SSL
  File "/usr/lib/python2.7/dist-packages/OpenSSL/SSL.py", line 105, in <module>
    SSL_ST_INIT = _lib.SSL_ST_INIT
AttributeError: 'module' object has no attribute 'SSL_ST_INIT'

Another idea to resolve this please ? :) Thanks a lot. F.

fabrice
  • 1,399
  • 1
  • 15
  • 27

2 Answers2

8

The problem is coming from pyopenssl. The first thing you can do is trying to remove and re-install pyopenssl :

apt-get --auto-remove --yes remove python-openssl
pip install pyOpenSSL

But it also could be a path problem.

Dadep
  • 2,796
  • 5
  • 27
  • 40
  • 2
    Thanks, it's working. I do this : "apt-get --auto-remove --yes remove python-openssl". And "python -m pip install --user --upgrade cryptography" 'cause there's an error during installing : "python -m pip install pyOpenSSL --user". For now, it's working :) – fabrice Jun 25 '18 at 14:47
  • The `pyopenssl` package may be installed via `pip` in which case the uninstall will be different - the key is to upgrade it to a recent version, see [this answer](https://stackoverflow.com/questions/45188413/python-pip-install-is-failing-with-attributeerror-module-object-has-no-att) for more on how to do this, including uninstalling `pyopenssl` installed via `pip`. – RichVel Nov 05 '19 at 10:15
3

Upgrading the OS-provided pip is a well-known 'own goal' and should be avoided unless absolutely necessary.

First, you may need to re-install the OS package, to restore normal use of the 'pip' command.

If you must have a newer pip: try installing it from a self-contained installer, see here: https://pip.pypa.io/en/stable/installing/ and not with the existing pip. Unless you must have it available for all users, run the install with '--user' option - and use the same option when installing packages with pip - that way you leave the OS-provided Python and pip things alone and don't overwrite them and can always return to them by deleting everything Python-related from ~/.local/.

In all cases, after you recover from pip being stuck as you have it right now, try upgrading pyOpenSSL first (or pip install-ing it with --user).

Another helpful tip that I found somewhere on the Web: always use python -m pip instead of running pip directly, this avoids problems with pip picking up the wrong version or the pip module (or running the wrong python executable, if you've got more than one).

Leo K
  • 5,189
  • 3
  • 12
  • 27
  • Thanks. I try to reinstall pip (using curl). And launch "python get-pip.py'. I've the same error : "AttributeError: 'module' object has no attribute 'SSL_ST_INIT'" (using "--user" too) – fabrice Jun 25 '18 at 09:51
  • I've no "~/.local/" folder – fabrice Jun 25 '18 at 09:54
  • "~/.local/" gets created if you use the `--user` option. – Leo K Jun 25 '18 at 10:12
  • I've the same error doing this : # python -m pip install --user --upgrade pyOpenSSL. The "~.local" gets **not** created :( – fabrice Jun 25 '18 at 13:22