[파이썬] pip install beautifulsoup4 설치시 오류 해결 방법

[파이썬] pip install beautifulsoup4 설치시 오류 해결 방법

크롤링을 하기위해서 beautifulsoup를 설치하게 됩니다.

파이참 툴을 사용중이라면 미설치된 라이브러리에 빨간줄이 생깁니다. 마우스 커서를 올리면 install package BeautifulSoup 처럼 파란색 글씨가 나타납니다.

클릭하여 설치할 수 도 있고, 단축키인 Alt+Shift+Enter 를 눌러서 설치할 수 도 있습니다.

설치할 때 다음과 같은 오류가 발생할 수 있어요.


Collecting BeautifulSoup Downloading BeautifulSoup-3.2.2.tar.gz (32 kB) DEPRECATION: The -b/--build/--build-dir/--build-directory option is deprecated. pip 20.3 will remove support for this functionality. A possible replacement is use the TMPDIR/TEMP/TMP environment variable, possibly combined with --no-clean. You can find discussion regarding this at https://github.com/pypa/pip/issues/8333. ERROR: Command errored out with exit status 1: command: 'C:\Users\ilike\AppData\Local\Programs\Python\Python39\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\ilike\\AppData\\Local\\Temp\\pycharm-packaging\\beautifulsoup\\setup.py'"'"'; __file__='"'"'C:\\Users\\ilike\\AppData\\Local\\Temp\\pycharm-packaging\\beautifulsoup\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\ilike\AppData\Local\Temp\pip-pip-egg-info-72zafi1p' cwd: C:\Users\ilike\AppData\Local\Temp\pycharm-packaging\beautifulsoup\ Complete output (6 lines): Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Users\ilike\AppData\Local\Temp\pycharm-packaging\beautifulsoup\setup.py", line 3 "You're trying to run a very old release of Beautiful Soup under Python 3. This will not work."<>"Please use Beautiful Soup 4, available through the pip package 'beautifulsoup4'." ^ SyntaxError: invalid syntax ---------------------------------------- ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output. WARNING: You are using pip version 20.2.3; however, version 20.3.1 is available. You should consider upgrading via the 'C:\Users\ilike\AppData\Local\Programs\Python\Python39\python.exe -m pip install --upgrade pip' command.

beautifulsoup 설치 오류 해결 방법

윈도우 작업표시줄에서 명령프롬프트(cmd) 창을 열고  pip 업그레이드 명령을 쳐서 업그레이드를 먼저 진행합니다.

python.exe -m pip install --upgrade pip
Microsoft Windows [Version 10.0.19042.685]
(c) 2020 Microsoft Corporation. All rights reserved.

C:\Users\ilike>python.exe -m pip install --upgrade pip
Collecting pip
  Downloading pip-20.3.1-py2.py3-none-any.whl (1.5 MB)
     |████████████████████████████████| 1.5 MB 6.4 MB/s
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 20.2.3
    Uninstalling pip-20.2.3:
      Successfully uninstalled pip-20.2.3
Successfully installed pip-20.3.1

C:\Users\ilike>

참고사항으로 파이썬3에서는 BeautifulSoup-3.2.2.버전을 사용할 수 없습니다.

BeautifulSoup 4를 사용해야합니다.

설치방법은 터미널창을 열거나 명령프롬프트(cmd)를 열고 pip install beautifulsoup4 명령어를 실행합니다.

C:\python\Workspace>
C:\python\Workspace>pip install beautifulsoup4
Collecting beautifulsoup4
  Downloading beautifulsoup4-4.9.3-py3-none-any.whl (115 kB)
     |████████████████████████████████| 115 kB 6.8 MB/s
Collecting soupsieve>1.2
  Downloading soupsieve-2.0.1-py3-none-any.whl (32 kB)
Installing collected packages: soupsieve, beautifulsoup4
Successfully installed beautifulsoup4-4.9.3 soupsieve-2.0.1

C:\python\Workspace>

또 다른 설치 방법은 os모듈을 import 후 os.system()함수를 사용하여 명령어를 실행할 수 있습니다.

>>> import os
>>>
>>> os.system("pip install beautifulsoup4")
Requirement already satisfied: beautifulsoup4 in c:\users\ilike\appdata\local\programs\python\python39\lib\site-packages (4.9.3)
Requirement already satisfied: soupsieve>1.2 in c:\users\ilike\appdata\local\programs\python\python39\lib\site-packages (from beautifulsoup4) (2.0.1)
>>>
>>>

마지막으로 import 해야하는 모듈을 변경해야 합니다.

AS-IS

import requests, BeautifulSoup

TO-BE

from bs4 import BeautifulSoup

[REFERENCE]

stackoverflow.com/questions/19957194/install-beautiful-soup-using-pip


카테고리의 다른 글
error: Content is protected !!