【问题标题】:updating python cryptography causes error and does not work scripts更新 python 加密会导致错误并且脚本不起作用
【发布时间】: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,安装pipsetuptoolsvirtualenv ,从那时起,永远不要使用pip 全局安装任何东西(apt 可以)。忘记sudo——在 Python 中你几乎不需要它。

标签: python pip cryptography


【解决方案1】:

试试

apt-get --auto-remove remove python-openssl

后跟pip install pyopenSSL

【讨论】:

  • 我已经更新了问题,你可以再看一遍
【解决方案2】:

您正在使用sudo 修改系统python 安装。这很危险,您可能已经修改了系统所依赖的库。请改用virtualenvvirtualenvwrapper

这里是使用 python2 运行的 virtualenvwrapper:

brew@ontario:~$ mkvirtualenv -p `which python2` crypto2
Running virtualenv with interpreter /usr/local/bin/python2
New python executable in /Users/brew/.virtualenvs/crypto2/bin/python2.7
Also creating executable in /Users/brew/.virtualenvs/crypto2/bin/python
Installing setuptools, pip, wheel...
done.
virtualenvwrapper.user_scripts creating /Users/brew/.virtualenvs/crypto2/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/brew/.virtualenvs/crypto2/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/brew/.virtualenvs/crypto2/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/brew/.virtualenvs/crypto2/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/brew/.virtualenvs/crypto2/bin/get_env_details
(crypto2) brew@ontario:~$ pip install --upgrade pip
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Requirement already up-to-date: pip in ./.virtualenvs/crypto2/lib/python2.7/site-packages (19.2.2)
(crypto2) brew@ontario:~$ pip install cryptography
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Collecting cryptography
  Downloading https://files.pythonhosted.org/packages/e2/bf/3b641820c561aedde134e88528ba68dffe41ed238899fab7f7ef20118aaf/cryptography-2.7-cp27-cp27m-macosx_10_6_intel.whl (1.6MB)
     |################################| 1.6MB 896kB/s
Collecting enum34; python_version < "3" (from cryptography)
  Using cached https://files.pythonhosted.org/packages/c5/db/e56e6b4bbac7c4a06de1c50de6fe1ef3810018ae11732a50f15f62c7d050/enum34-1.1.6-py2-none-any.whl
Collecting cffi!=1.11.3,>=1.8 (from cryptography)
  Downloading https://files.pythonhosted.org/packages/16/f6/46a3dece43541b2cbf3776ec2299e370a2408d9380958401cacb6d101853/cffi-1.12.3-cp27-cp27m-macosx_10_6_intel.whl (245kB)
     |################################| 256kB 6.6MB/s
Collecting six>=1.4.1 (from cryptography)
  Using cached https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Collecting asn1crypto>=0.21.0 (from cryptography)
  Using cached https://files.pythonhosted.org/packages/ea/cd/35485615f45f30a510576f1a56d1e0a7ad7bd8ab5ed7cdc600ef7cd06222/asn1crypto-0.24.0-py2.py3-none-any.whl
Collecting ipaddress; python_version < "3" (from cryptography)
  Downloading https://files.pythonhosted.org/packages/fc/d0/7fc3a811e011d4b388be48a0e381db8d990042df54aa4ef4599a31d39853/ipaddress-1.0.22-py2.py3-none-any.whl
Collecting pycparser (from cffi!=1.11.3,>=1.8->cryptography)
Installing collected packages: enum34, pycparser, cffi, six, asn1crypto, ipaddress, cryptography
Successfully installed asn1crypto-0.24.0 cffi-1.12.3 cryptography-2.7 enum34-1.1.6 ipaddress-1.0.22 pycparser-2.19 six-1.12.0
(crypto2) brew@ontario:~$ deactivate
brew@ontario:~$ 

python3 也一样:

brew@ontario:~$ mkvirtualenv -p `which python3` crypto3
Running virtualenv with interpreter /usr/local/bin/python3
Using base prefix '/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7'
New python executable in /Users/brew/.virtualenvs/crypto3/bin/python3.7
Also creating executable in /Users/brew/.virtualenvs/crypto3/bin/python
Installing setuptools, pip, wheel...
done.
virtualenvwrapper.user_scripts creating /Users/brew/.virtualenvs/crypto3/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/brew/.virtualenvs/crypto3/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/brew/.virtualenvs/crypto3/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/brew/.virtualenvs/crypto3/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/brew/.virtualenvs/crypto3/bin/get_env_details
(crypto3) brew@ontario:~$ pip install --upgrade pip
Requirement already up-to-date: pip in ./.virtualenvs/crypto3/lib/python3.7/site-packages (19.2.2)
(crypto3) brew@ontario:~$ pip install cryptography
Collecting cryptography
  Using cached https://files.pythonhosted.org/packages/63/4e/57b7a6bd98906872fcd2531e74b532de2abe17d675a5cf171931fcb4a9e8/cryptography-2.7-cp34-abi3-macosx_10_6_intel.whl
Collecting six>=1.4.1 (from cryptography)
  Using cached https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Collecting cffi!=1.11.3,>=1.8 (from cryptography)
  Using cached https://files.pythonhosted.org/packages/f0/48/5aa4ea664eba26dd5142558d04762f5065c02220b4665b3f7eecb9bb614e/cffi-1.12.3-cp37-cp37m-macosx_10_9_x86_64.whl
Collecting asn1crypto>=0.21.0 (from cryptography)
  Using cached https://files.pythonhosted.org/packages/ea/cd/35485615f45f30a510576f1a56d1e0a7ad7bd8ab5ed7cdc600ef7cd06222/asn1crypto-0.24.0-py2.py3-none-any.whl
Collecting pycparser (from cffi!=1.11.3,>=1.8->cryptography)
Installing collected packages: six, pycparser, cffi, asn1crypto, cryptography
Successfully installed asn1crypto-0.24.0 cffi-1.12.3 cryptography-2.7 pycparser-2.19 six-1.12.0
(crypto3) brew@ontario:~$ deactivate 
brew@ontario:~$ 

【讨论】:

  • 谢谢,从现在开始我会以这种方式工作,我认为这样会更安全,更干净,不会出现错误
  • 酷。祝你好运@Jonaa
猜你喜欢
  • 2020-05-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-09
  • 2021-10-15
  • 1970-01-01
  • 2019-02-16
相关资源
最近更新 更多