pip 그리고 python library 설치.
python으로 코딩하거나 기존에 구현된 python script를 가져다 쓰다보면 import error가 발생하는 경우가 있다.
그 이유는 사용하고자 하는 python library가 설치되어 있지 않았기 때문이다.
그렇다면 원하는 python library를 설치하는 방법에 대해 예를 들어 보며 확인해 보자.
>>> import hexdump
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named hexdump
>>>
"No module named hexdump" ....
여기서는 hexdump library가 없다는 에러 메세지이다.
hexdump로 package search를 해보았지만 별다르게 포함하고 있을 법한 패키지는 보이지 않는다.
어떻게 설치해야 할까.
$ apt-cache search hexdump
bsdmainutils - collection of more utilities from FreeBSD
libdata-hexdumper-perl - module for formatting binary data in a human-readable way
libghc-crypto-dev - cryptographical algorithms for Haskell
libghc-crypto-doc - cryptographical algorithms for Haskell; documentation
libghc-crypto-prof - cryptographical algorithms for Haskell; profiling libraries
libmatthew-debug-java - Debugging library for Java
tcpick - TCP stream sniffer and connection tracker
python은 python package를 설치하는 명령어가 별도로 있다.
pip (A tool for installing and managing Python packages)
$ apt-get install python-pip
python-pip를 설치하면 pip를 사용할 수 있다.
python package를 설치하기 위한 pip를 설치하였으므로 위의 python library인 hexdump는 pip로 설치하면 된다.
# pip install hexdump
Downloading/unpacking hexdump
Downloading hexdump-3.3.zip
Running setup.py (path:/tmp/pip_build_root/hexdump/setup.py) egg_info for package hexdump
Installing collected packages: hexdump
Running setup.py install for hexdump
Successfully installed hexdump
Cleaning up...
위와 같이 설치하면 아래와 같이 사용이 가능해 진다.
이제부터는 python 관련 package들은 apt-get을 이용하지 말고, pip를 이용하도록 하자.
>>> import hexdump
>>>
Reference