2

Cannot import or even install anything using pip after installing pyopenssl. Getting the following error

***Traceback (most recent call last):
  File "/usr/local/bin/pip3", line 11, in <module>
    sys.exit(main())
  File "/home/srnadmin/.local/lib/python3.5/site-packages/pip/_internal/cli/main.py", line 73, in main
    command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
  File "/home/srnadmin/.local/lib/python3.5/site-packages/pip/_internal/commands/__init__.py", line 96, in create_command
    module = importlib.import_module(module_path)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/srnadmin/.local/lib/python3.5/site-packages/pip/_internal/commands/install.py", line 24, in <module>
    from pip._internal.cli.req_command import RequirementCommand
  File "/home/srnadmin/.local/lib/python3.5/site-packages/pip/_internal/cli/req_command.py", line 15, in <module>
    from pip._internal.index.package_finder import PackageFinder
  File "/home/srnadmin/.local/lib/python3.5/site-packages/pip/_internal/index/package_finder.py", line 21, in <module>
    from pip._internal.index.collector import parse_links
  File "/home/srnadmin/.local/lib/python3.5/site-packages/pip/_internal/index/collector.py", line 12, in <module>
    from pip._vendor import html5lib, requests
  File "/home/srnadmin/.local/lib/python3.5/site-packages/pip/_vendor/requests/__init__.py", line 97, in <module>
    from pip._vendor.urllib3.contrib import pyopenssl
  File "/home/srnadmin/.local/lib/python3.5/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.py", line 46, in <module>
    import OpenSSL.SSL
  File "/usr/local/lib/python3.5/dist-packages/OpenSSL/__init__.py", line 8, in <module>
    from OpenSSL import crypto, SSL
  File "/usr/local/lib/python3.5/dist-packages/OpenSSL/crypto.py", line 15, in <module>
    from OpenSSL._util import (
  File "/usr/local/lib/python3.5/dist-packages/OpenSSL/_util.py", line 152, in <module>
    with ffi.from_buffer(b""):
TypeError: from_buffer() cannot return the address of the raw string within a bytes or unicode or bytearray object***

Can anyone please help me with this?

kkawatra
  • 49
  • 5

2 Answers2

2

Got it to work

rm -rf /usr/local/lib/python3.5/dist-packages/OpenSSL/

pip3 uninstall pyopenssl

easy_install pyopenssl

kkawatra
  • 49
  • 5
2

It happened to me as well. (I'm running Python 3.7 on MacOS Catalina with Anaconda).

So apparently that's a problem with either cryptography module. Even pip uninstall wasn't working.

You could use this link for finding out the location of the cryptography package and delete it. Once deleted, just do pip install --upgrade cryptography and it will just work fine.

But in my case that wasn't working. So here's what I did:

  1. Activate your env which has this problem. That could be done using conda activate <env_name> or source <path_to_env>/bin/activate. (If there's no env, just skip this step)
  2. Next execute where python or just conda info --envs if you're using anaconda. This should give you the path to the python executable. In my case it was ~/opt/anaconda3 as the output for conda info --envs.

  3. Next just cd into that directory and then remove (or move it somewhere else in case you want a backup) the ~/opt/anaconda3/bin/python/cryptography folder. Or you could even do find . | grep cryptography after cding in the particular env folder to know the exact location of the package.

  4. Next execute pip install --upgrade cryptography. In case that didn't work, you could try the same with the pyopenssl package.

Hope it helped.

Arpan Srivastava
  • 356
  • 5
  • 10