【发布时间】:2019-08-14 03:38:08
【问题描述】:
我正在尝试更新 Python 加密,但发生了一个错误,导致我几乎无法运行任何脚本
我尝试了不同的方法来更新它,但它仍然发生在我的 Linux PC“ubuntu”32 位
sudo pip install cryptography --upgrade
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
from pip import main
ImportError: cannot import name main
他试图更新它,因为每次他运行一系列脚本时,他都会向我显示一个他以前没有做过的错误
运行脚本时的错误消息:
Traceback (most recent call last):
File "fbi.py", line 21, in <module>
import requests
File "/home/elvaquero/.local/lib/python2.7/site-packages/requests/__init__.py", line 95, in <module>
from urllib3.contrib import pyopenssl
File "/home/elvaquero/.local/lib/python2.7/site-packages/urllib3/contrib/pyopenssl.py", line 46, in <module>
import OpenSSL.SSL
File "build/bdist.linux-i686/egg/OpenSSL/__init__.py", line 8, in <module>
File "build/bdist.linux-i686/egg/OpenSSL/SSL.py", line 194, in <module>
AttributeError: 'module' object has no attribute 'Cryptography_HAS_SSL_ST'
我试过这个
$ apt-get --auto-remove remove python-openssl
尝试命令时
$ pip install pyopenSSL
返回以下错误:
Traceback (last most recent call):
File "/ usr / bin / pip", line 9, in <module>
from pip import main
ImportError: the name main cannot be imported
我然后试试
$ sudo apt install --reinstall python-openssl
已正确安装,但错误仍然出现。
$ python example.py
Traceback (most recent call last):
File "fbi.py", line 21, in <module>
import requests
File "/home/elvaquero/.local/lib/python2.7/site-packages/requests/__init__.py", line 95, in <module>
from urllib3.contrib import pyopenssl
File "/home/elvaquero/.local/lib/python2.7/site-packages/urllib3/contrib/pyopenssl.py", line 46, in <module>
import OpenSSL.SSL
File "build/bdist.linux-i686/egg/OpenSSL/__init__.py", line 8, in <module>
File "build/bdist.linux-i686/egg/OpenSSL/SSL.py", line 194, in <module>
AttributeError: 'module' object has no attribute 'Cryptography_HAS_SSL_ST'
我发现你也可以试试
$ sudo easy_install -U cffi $ sudo easy_install -U 密码学
但它也不起作用
$ sudo easy_install -U cffi
Searching for cffi
Reading https://pypi.python.org/simple/cffi/
Best match: cffi 1.12.3
Downloading https://files.pythonhosted.org/packages/93/1a/ab8c62b5838722f29f3daffcc8d4bd61844aa9b5f437341cc890ceee483b/cffi-1.12.3.tar.gz#sha256=041c81822e9f84b1d9c401182e174996f0bae9991f33725d059b771744290774
Processing cffi-1.12.3.tar.gz
Writing /tmp/easy_install-2lyiDA/cffi-1.12.3/setup.cfg
Running cffi-1.12.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-2lyiDA/cffi-1.12.3/egg-dist-tmp-yrDbvQ
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing `libffi.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libffi' found
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing `libffi.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libffi' found
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing `libffi.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libffi' found
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing `libffi.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libffi' found
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing `libffi.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libffi' found
c/_cffi_backend.c:2:20: fatal error: Python.h: No existe el fichero o el directorio
compilation terminated.
error: Setup script exited with error: command 'i686-linux-gnu-gcc' failed with exit status 1
$ sudo easy_install -U cryptography
Searching for cryptography
Reading https://pypi.python.org/simple/cryptography/
Best match: cryptography 2.7
Downloading https://files.pythonhosted.org/packages/c2/95/f43d02315f4ec074219c6e3124a87eba1d2d12196c2767fadfdc07a83884/cryptography-2.7.tar.gz#sha256=e6347742ac8f35ded4a46ff835c60e68c22a536a8ae5c4422966d06946b6d4c6
Processing cryptography-2.7.tar.gz
Writing /tmp/easy_install-nKssiw/cryptography-2.7/setup.cfg
Running cryptography-2.7/setup.py -q bdist_egg --dist-dir /tmp/easy_install-nKssiw/cryptography-2.7/egg-dist-tmp-e9llQ5
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'python_requires'
warnings.warn(msg)
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'long_description_content_type'
warnings.warn(msg)
no previously-included directories found matching 'docs/_build'
warning: no previously-included files found matching 'vectors'
warning: no previously-included files matching '*' found under directory 'vectors'
warning: no previously-included files found matching 'azure-pipelines.yml'
warning: no previously-included files found matching '.azure-pipelines'
warning: no previously-included files found matching '.travis.yml'
warning: no previously-included files found matching '.travis'
warning: no previously-included files matching '*' found under directory '.azure-pipelines'
warning: no previously-included files matching '*' found under directory '.travis'
warning: no previously-included files found matching 'release.py'
warning: no previously-included files found matching '.coveragerc'
warning: no previously-included files found matching 'codecov.yml'
warning: no previously-included files found matching 'dev-requirements.txt'
warning: no previously-included files found matching 'rtd-requirements.txt'
warning: no previously-included files found matching 'tox.ini'
build/temp.linux-i686-2.7/_openssl.c:22:24: fatal error: pyconfig.h: No existe el fichero o el directorio
compilation terminated.
error: Setup script exited with error: command 'i686-linux-gnu-gcc' failed with exit status 1
【问题讨论】:
-
@phd 我已更新问题,您可以再次查看,如有必要,请删除重复项。
-
现在,当你的系统Python这么坏的时候,我的建议是卸载它,彻底清除所有与Python相关的系统目录,重新安装Python,安装
pip、setuptools和virtualenv,从那时起,永远不要使用pip全局安装任何东西(apt可以)。忘记sudo——在 Python 中你几乎不需要它。
标签: python pip cryptography