본문 바로가기
건설 정보/Working Tool

matplotlib 설치 난항 : sudo와 sudo -H의 차이??

by 그로업 2017. 12. 10.

matplotlib, numpy, scipy 를 설치하려 하니


$ sudo pip install matplotlib ...


등으로 하면, 

sanghumcho@SanghumCHO:~$ sudo pip install matplotlib

[sudo] password for sanghumcho: 

The directory '/home/sanghumcho/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

The directory '/home/sanghumcho/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

Collecting matplotlib

  Downloading matplotlib-2.1.0-cp27-cp27mu-manylinux1_x86_64.whl (14.9MB)

    100% |████████████████████████████████| 14.9MB 23kB/s 

Requirement already satisfied: numpy>=1.7.1 in /usr/local/lib/python2.7/dist-packages (from matplotlib)

Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python2.7/dist-packages (from matplotlib)

Requirement already satisfied: six>=1.10 in /usr/local/lib/python2.7/dist-packages (from matplotlib)

Requirement already satisfied: pytz in /usr/local/lib/python2.7/dist-packages (from matplotlib)

Collecting subprocess32 (from matplotlib)

  Downloading subprocess32-3.2.7.tar.gz (54kB)

    100% |████████████████████████████████| 61kB 79kB/s 

Collecting python-dateutil>=2.0 (from matplotlib)

  Downloading python_dateutil-2.6.1-py2.py3-none-any.whl (194kB)

    100% |████████████████████████████████| 194kB 84kB/s 

Collecting backports.functools-lru-cache (from matplotlib)

  Downloading backports.functools_lru_cache-1.4-py2.py3-none-any.whl

Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 (from matplotlib)

  Downloading pyparsing-2.2.0-py2.py3-none-any.whl (56kB)

    100% |████████████████████████████████| 61kB 52kB/s 

Installing collected packages: subprocess32, python-dateutil, backports.functools-lru-cache, pyparsing, matplotlib

  Running setup.py install for subprocess32 ... error

    Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-RjBT2G/subprocess32/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-9Y_kA0-record/install-record.txt --single-version-externally-managed --compile:

    running install

    running build

    running build_py

    creating build

    creating build/lib.linux-x86_64-2.7

    copying subprocess32.py -> build/lib.linux-x86_64-2.7

    running build_ext

    building '_posixsubprocess' extension

    creating build/temp.linux-x86_64-2.7

    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c _posixsubprocess.c -o build/temp.linux-x86_64-2.7/_posixsubprocess.o

    _posixsubprocess.c:3:20: fatal error: Python.h: No such file or directory

    compilation terminated.

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

    

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

Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-RjBT2G/subprocess32/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-9Y_kA0-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-RjBT2G/subprocess32/


의 Warning message가 뜬다.

다행히, 이넘이 하라는대로 '-H' flag를 첨가하여


$ sudo -H pip install numpy ...


를 적용하니, 정상적으로 설치가 된다.


http://goodjoon.tistory.com/101 를 참조하면

Ubuntu 에서 특정 사용자의 VirtualBox VM을 root 계정을 통해 실행시키려 했더니,

COM 초기화 실패 에러가 난다. 왜그런가 했더니, 특정 사용자의 Home 디렉토리 환경이 안잡힌게 문제였다.


보통 sudo 사용 시

$ sudo -u userid 커맨드..

사용하는데, 이것 말고, 한가지 옵션 (-H ) 만 더 넣어주면 해결 된다.


즉,

$ sudo -H -u userid 커맨드...

처럼 -H 옵션을 넣어주면, 사용자의 Home 디렉토리를 사용하게 된다.


이라고 되어있는데... 무슨 말인지 모르겠다.

https://stackoverflow.com/questions/27870003/pip-install-please-check-the-permissions-and-owner-of-that-directory

https://stackoverflow.com/questions/28619686/what-is-the-h-flag-for-pip


를 참조하면, sudo 명령어에 대한 '-H' flag는 root 계정이 아닌, 특정 사용자의 디렉토리를 사용한다는 것인데...

잘 모르겠다. 일단 잘 설치 됐으니 그걸로 된거지 뭐


설치는 되나, import 안된다.


sanghumcho@SanghumCHO:~$ sudo -H pip install pillow

[sudo] password for sanghumcho: 

Collecting pillow

  Downloading Pillow-4.3.0-cp27-cp27mu-manylinux1_x86_64.whl (5.8MB)

    100% |████████████████████████████████| 5.8MB 134kB/s 

Collecting olefile (from pillow)

  Downloading olefile-0.44.zip (74kB)

    100% |████████████████████████████████| 81kB 300kB/s 

Building wheels for collected packages: olefile

  Running setup.py bdist_wheel for olefile ... done

  Stored in directory: /root/.cache/pip/wheels/20/58/49/cc7bd00345397059149a10b0259ef38b867935ea2ecff99a9b

Successfully built olefile

Installing collected packages: olefile, pillow

Successfully installed olefile-0.44 pillow-4.3.0

sanghumcho@SanghumCHO:~$ source activate tf1

(tf1) sanghumcho@SanghumCHO:~$ cd Downloads

(tf1) sanghumcho@SanghumCHO:~/Downloads$ python test.py

Using TensorFlow backend.

Traceback (most recent call last):

  File "test.py", line 7, in <module>

    from PIL import Image

ModuleNotFoundError: No module named 'PIL'


현재 PIL case를 보여주었지만, matplotlib도 똑같은 증상임. (설치는 되었으나, import가 안됨.)


.

.

.

다 필요없다.


matplotlib offical URL : http://matplotlib.org/users/installing.html#installing


위 공식 URL을 참조하면, 


$ python -mpip install -U pip

$ python -mpip install -U matplotlib


을 하니까 한방에 설치된다.

물론, tensorflow가 설치된 $ source activate 를 통해 작업환경에 들어가서 설치해야 함.


그나저나 Error의 이유를 모르고 해결을 하니, 굉장히 찝찝한 기분이 든다.

.

.

.

PIL(Pillow)도 pip install이 아닌 python -mpip install 을 하니, 제대로 적용된다. 대체 차이가 뭘까... 후..

댓글