본문 바로가기
놀기/에러 잡기

pycrypto 설치하기 (ModuleNotFoundError: No module named 'Crypto')

by Hi~ 2021. 10. 30.

파이썬에서 Crypto.Random를 사용하려고 하는데 설치가 안돼서 이리저리 찾아본 후에 정리를 한다.

 

일단 pycrypto를 설치하라고 하는데 에러가 난다.

 

$ pip install pycrypto
Collecting pycrypto
  Using cached pycrypto-2.6.1.tar.gz (446 kB)
Building wheels for collected packages: pycrypto
  Building wheel for pycrypto (setup.py) ... error

/* 중략 */

-Isrc/ -I/usr/include/python3.8 -c src/MD2.c -o build/temp.linux-x86_64-3.8/src/MD2.o
    src/MD2.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: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-jgucyvh9/pycrypto/setup.py'"'"'; __file__='"'"'/tmp/pip-install-jgucyvh9/pycrypto/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-48y5g743/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/dev/.local/include/python3.8/pycrypto Check the logs for full command output.
$

 

fatal error: Python.h: No such file or directory 에러가 나오는 것으로 봐서 빌드용 라이브러리가 필요하다.

 

$ sudo apt-get install python3-dev

/* 중략 */

The following packages have unmet dependencies:
 python3.8-dev : Depends: zlib1g-dev but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

/* zlib1g-dev 가 없다고 해서 설치... */

$ sudo apt-get install zlib1g-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 zlib1g-dev : Depends: zlib1g (= 1:1.2.11.dfsg-2ubuntu1) but 1:1.2.11.dfsg-2ubuntu1.2 is to be installed
E: Unable to correct problems, you have held broken packages.
$

 

뭐가 필요하다고 해서 설치했는데 이것도 에러가 난다. 

 

여기서 부터 해결책!!

 

1. aptitude를 설치하자.

$ sudo apt-get install aptitude

 

2. aptitude를 사용해서 python3.8-dev를 설치하자. 주의할 것은 처음에는 n를 선택하고 두 번째에서 y를 선택한다.

$ sudo aptitude install python3.8-dev
The following NEW packages will be installed:
  libexpat1-dev{a} libpython3.8-dev{a} python3.8-dev zlib1g-dev{ab} 
0 packages upgraded, 4 newly installed, 0 to remove and 127 not upgraded.
Need to get 4,729 kB of archives. After unpacking 22.0 MB will be used.
The following packages have unmet dependencies:
 zlib1g-dev : Depends: zlib1g (= 1:1.2.11.dfsg-2ubuntu1) but 1:1.2.11.dfsg-2ubuntu1.2 is installed
The following actions will resolve these dependencies:

     Keep the following packages at their current version:
1)     python3.8-dev [Not Installed]                      
2)     zlib1g-dev [Not Installed]                         


Accept this solution? [Y/n/q/?] n /// 여기서는 "n" 선택
The following actions will resolve these dependencies:

     Downgrade the following packages:                                          
1)     zlib1g [1:1.2.11.dfsg-2ubuntu1.2 (now) -> 1:1.2.11.dfsg-2ubuntu1 (focal)]



Accept this solution? [Y/n/q/?] y /// 여기서는 "y" 선택
The following packages will be DOWNGRADED:
  zlib1g 
The following NEW packages will be installed:
  libexpat1-dev{a} libpython3.8-dev{a} python3.8-dev zlib1g-dev{a} 
0 packages upgraded, 4 newly installed, 1 downgraded, 0 to remove and 127 not upgraded.
Need to get 4,783 kB of archives. After unpacking 22.0 MB will be used.
Do you want to continue? [Y/n/?] y
Get: 1 http://kr.archive.ubuntu.com/ubuntu focal/main amd64 zlib1g amd64 1:1.2.11.dfsg-2ubuntu1 [53.7 kB]
Get: 2 http://security.ubuntu.com/ubuntu focal-security/main amd64 libpython3.8-dev amd64 3.8.10-0ubuntu1~20.04.1 [3,948 kB]
Get: 3 http://kr.archive.ubuntu.com/ubuntu focal/main amd64 libexpat1-dev amd64 2.2.9-1build1 [116 kB]
Get: 4 http://kr.archive.ubuntu.com/ubuntu focal/main amd64 zlib1g-dev amd64 1:1.2.11.dfsg-2ubuntu1 [156 kB]
Get: 5 http://security.ubuntu.com/ubuntu focal-security/main amd64 python3.8-dev amd64 3.8.10-0ubuntu1~20.04.1 [510 kB]
Fetched 4,783 kB in 3s (1,410 kB/s)
dpkg: warning: downgrading zlib1g:amd64 from 1:1.2.11.dfsg-2ubuntu1.2 to 1:1.2.11.dfsg-2ubuntu1
(Reading database ... 179618 files and directories currently installed.)
Preparing to unpack .../zlib1g_1%3a1.2.11.dfsg-2ubuntu1_amd64.deb ...
Unpacking zlib1g:amd64 (1:1.2.11.dfsg-2ubuntu1) over (1:1.2.11.dfsg-2ubuntu1.2) ...
Setting up zlib1g:amd64 (1:1.2.11.dfsg-2ubuntu1) ...
Selecting previously unselected package libexpat1-dev:amd64.
(Reading database ... 179618 files and directories currently installed.)
Preparing to unpack .../libexpat1-dev_2.2.9-1build1_amd64.deb ...
Unpacking libexpat1-dev:amd64 (2.2.9-1build1) ...
Selecting previously unselected package libpython3.8-dev:amd64.
Preparing to unpack .../libpython3.8-dev_3.8.10-0ubuntu1~20.04.1_amd64.deb ...
Unpacking libpython3.8-dev:amd64 (3.8.10-0ubuntu1~20.04.1) ...
Selecting previously unselected package zlib1g-dev:amd64.
Preparing to unpack .../zlib1g-dev_1%3a1.2.11.dfsg-2ubuntu1_amd64.deb ...
Unpacking zlib1g-dev:amd64 (1:1.2.11.dfsg-2ubuntu1) ...
Selecting previously unselected package python3.8-dev.
Preparing to unpack .../python3.8-dev_3.8.10-0ubuntu1~20.04.1_amd64.deb ...
Unpacking python3.8-dev (3.8.10-0ubuntu1~20.04.1) ...
Setting up libexpat1-dev:amd64 (2.2.9-1build1) ...
Setting up libpython3.8-dev:amd64 (3.8.10-0ubuntu1~20.04.1) ...
Setting up zlib1g-dev:amd64 (1:1.2.11.dfsg-2ubuntu1) ...
Setting up python3.8-dev (3.8.10-0ubuntu1~20.04.1) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...

 

3. pycrypto 설치하기

아래와 같이 설치 성공!!!

$ pip install pycrypto
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-cp38-cp38-linux_x86_64.whl size=498472 sha256=221ff54f3c54a00bac6da14fb36e12dc4c5e701743cc4e953ad82c3cf3de6234
  Stored in directory: /home/dev/.cache/pip/wheels/d0/99/d0/0298ea019d63f1d63a0965b9944b719e875f9bd6ffc6dcf293
Successfully built pycrypto
Installing collected packages: pycrypto
Successfully installed pycrypto-2.6.1
$

 

 

 

댓글