ubuntu python2.7 ImportError: No module named Crypto.Cipher 解决办法

原因是缺少一个库,pip是python的库管理工具,我们需要用pip安装这个库,所以需要先安装pip,每个python版本有不同的pip版本,

首先要确认 python 版本是 2.7,确认是否安装对应版本的 pip,如果没有先安装 pip,一般用 ez install 脚本安装,先下载,再执行

下载get-pip.py

sunzy@sunzy:/usr/lib/python2.7$ sudo curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py

  % Total    % Received % Xferd  Average Speed  Time    Time    Time  Current

                                Dload  Upload  Total  Spent    Left  Speed

100 1863k  100 1863k   0     0   7387     0  0:04:18  0:04:18 --:--:-- 36638

执行 get-pip.py

sunzy@sunzy:/usr/lib/python2.7$ sudo python get-pip.py

DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.

Collecting pip<21.0

  Using cached pip-20.3.4-py2.py3-none-any.whl (1.5 MB)

Collecting setuptools<45

  Downloading setuptools-44.1.1-py2.py3-none-any.whl (583 kB)

     |████████████████████████████████| 583 kB 30 kB/s 

Collecting wheel

  Downloading wheel-0.37.1-py2.py3-none-any.whl (35 kB)

Installing collected packages: pip, setuptools, wheel

Successfully installed pip-20.3.4 setuptools-44.1.1 wheel-0.37.1

然后用 pip 安装 pycrypto

sunzy@sunzy:/usr/lib/python2.7$ sudo pip install pycrypto

DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.

Collecting pycrypto

  Downloading pycrypto-2.6.1.tar.gz (446 kB)

     |████████████████████████████████| 446 kB 86 kB/s 

Building wheels for collected packages: pycrypto

如果报错

src/_fastmath.c:31:10: fatal error: Python.h: No such file or directory

     31 | #include "Python.h"

       |          ^~~~~~~~~~

  compilation terminated.

  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

  ----------------------------------------

  ERROR: Failed building wheel for pycrypto

需要安装 pthon-dev

sunzy@sunzy:/usr/lib/python2.7$ sudo apt-get install python-dev

最后用 pip 安装 pycrypto 即可

sunzy@sunzy:/usr/lib/python2.7$ sudo pip install pycrypto

DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.

Collecting pycrypto

  Using cached pycrypto-2.6.1.tar.gz (446 kB)

Building wheels for collected packages: pycrypto

  Building wheel for pycrypto (setup.py) ... done

  Created wheel for pycrypto: filename=pycrypto-2.6.1-cp27-cp27mu-linux_x86_64.whl size=527375 sha256=24c7b9edddac6f8ee3e86e43f58b5e309c8683a8fa8ae81695481de96b245876

  Stored in directory: /root/.cache/pip/wheels/b6/e6/c8/d1eca13628952ceec1d40d96e0a7a1380460d2349ce0b85312

Successfully built pycrypto

Installing collected packages: pycrypto

Successfully installed pycrypto-2.6.1

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值