我在这个论坛上搜索了同样的问题,但没有任何修复对我有用。我有一台 Ubuntu 18.04,任何需要 OpenSSL 的 python 2.7 模块都会出现属性错误。Pip install 命令总是给出属性错误,但 pip freeze 命令有效。
我尝试(但没有成功)以下命令:
pip install -U pyopenssl
rm -rf /usr/lib/python2.7/dist-packages/OpenSSL
rm -rf /usr/lib/python2.7/dist-packages/pyOpenSSL-17.5.0.egg-info
pip install pyopenssl
python2.7 -m pip install --upgrade pip setuptools wheel
easy_install --upgrade pyOpenSSL
任何建议将不胜感激!
$ pip install pyopenssl
Traceback (most recent call last):
File "/usr/local/bin/pip", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/pip/_internal/cli/main.py", line 73, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "/usr/local/lib/python2.7/dist-packages/pip/_internal/commands/__init__.py", line 104, in create_command
module = importlib.import_module(module_path)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/pip/_internal/commands/install.py", line 24, in <module>
from pip._internal.cli.req_command import RequirementCommand, with_cleanup
File "/usr/local/lib/python2.7/dist-packages/pip/_internal/cli/req_command.py", line 16, in <module>
from pip._internal.index.package_finder import PackageFinder
File "/usr/local/lib/python2.7/dist-packages/pip/_internal/index/package_finder.py", line 21, in <module>
from pip._internal.index.collector import parse_links
File "/usr/local/lib/python2.7/dist-packages/pip/_internal/index/collector.py", line 14, in <module>
from pip._vendor import html5lib, requests
File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/__init__.py", line 97, 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 "build/bdist.linux-x86_64/egg/OpenSSL/__init__.py", line 8, in <module>
File "build/bdist.linux-x86_64/egg/OpenSSL/SSL.py", line 118, in <module>
AttributeError: 'module' object has no attribute 'SSL_ST_INIT'
需要 OpenSSL 的命令示例
$ openstack
Traceback (most recent call last):
File "/usr/bin/openstack", line 6, in <module>
from openstackclient.shell import main
File "/usr/lib/python2.7/dist-packages/openstackclient/shell.py", line 22, in <module>
from osc_lib.api import auth
File "/usr/lib/python2.7/dist-packages/osc_lib/api/auth.py", line 19, in <module>
from keystoneauth1.loading import base
File "/usr/lib/python2.7/dist-packages/keystoneauth1/loading/__init__.py", line 13, in <module>
from keystoneauth1.loading import adapter
File "/usr/lib/python2.7/dist-packages/keystoneauth1/loading/adapter.py", line 13, in <module>
from keystoneauth1 import adapter
File "/usr/lib/python2.7/dist-packages/keystoneauth1/adapter.py", line 16, in <module>
from keystoneauth1 import session
File "/usr/lib/python2.7/dist-packages/keystoneauth1/session.py", line 25, in <module>
import requests
File "/usr/local/lib/python2.7/dist-packages/requests/__init__.py", line 95, in <module>
from urllib3.contrib import pyopenssl
File "/usr/local/lib/python2.7/dist-packages/urllib3/contrib/pyopenssl.py", line 46, in <module>
import OpenSSL.SSL
File "build/bdist.linux-x86_64/egg/OpenSSL/__init__.py", line 8, in <module>
File "build/bdist.linux-x86_64/egg/OpenSSL/SSL.py", line 118, in <module>
AttributeError: 'module' object has no attribute 'SSL_ST_INIT'
答案1
下面的命令起了作用。
python2.7 -m easy_install --upgrade pyOpenSSL