[파이썬 Python] mac버전으로 Python에 BeautifulSoup 설치하기

Posted by 두두오빠
2017. 9. 6. 23:30 프로그래밍/파이썬 Python

python 사용을 위해서, window 환경에는 설치를 완료했고, 개인적으로 사용하는 mac에도 설치를 해봤다. python 을 다운로드 받고, 실행까지 잘 되는 것을 확인할 수 있었다. 하지만, BeautifulSoup 사용을 위한 설치도중에 문제에 계속 걸렸다.


검색중에 mac에는 이미 python이 설치되어 있다는 것을 알았다. terminal 에서 python 을 실행하면, 현재 작동 가능한 버전의 python이 실행된다. 현재 가능한 버전은 2.7.10 이다. 나는 python 을 설치한 적이 없지만, 이미 2015년부터 설치가 되어 있었다라고 나온다.






Python에 BeautifulSoup 설치하기

다운로드 받은, BeautifulSoup 파일의 경로를 확인하여, 해당 경로에 들어간다.


cd /Applications/beautifulsoup4-4.6.0


다음 명령을 실행시키면 python 에 BeautifulSoup 가 설치된다.

Kim-ui-MacBook-Air:beautifulsoup4-4.6.0 kkk$ python setup.py install



BeautifulSoup 설치중에 다음과 같은 메시지가 나온다.


running install

Checking .pth file support in /Library/Python/2.7/site-packages/

error: can't create or remove files in install directory


The following error occurred while trying to add or remove files in the

installation directory:


    [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/test-easy-install-35586.pth'


The installation directory you specified (via --install-dir, --prefix, or

the distutils default setting) was:


    /Library/Python/2.7/site-packages/


Perhaps your account does not have write access to this directory?  If the

installation directory is a system-owned directory, you may need to sign in

as the administrator or "root" account.  If you do not have administrative

access to this machine, you may wish to choose a different installation

directory, preferably one that is listed in your PYTHONPATH environment

variable.


For information on other options, you may wish to consult the

documentation at:


  https://pythonhosted.org/setuptools/easy_install.html


Please make the appropriate changes for your system and try again.



권한이 없어서 실행할 수 없다는 에러메시지 확인할 수 있다. permission을 주기 위해 sudo를 사용한다. 

> sudo python setup.py install


Kim-ui-MacBook-Air:beautifulsoup4-4.6.0 kkk$ sudo python setup.py install

Password:


정상적으로 설치 완료!

이제 파이썬으로 들어가서 설치여부를 확인해보면 된다. 다음 명령이 아무 문제 없이 실행된다면, 정상적으로 설치완료

>>> from bs4 import BeautifulSoup