티스토리 뷰

반응형

Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.

Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.

 

아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.

Import error: No module name urllib2

가져오기 오류: No module name urllib2

 문제 내용 

Here's my code:

제 코드는 이렇습니다.

 

import urllib2.request

response = urllib2.urlopen("http://www.google.com")
html = response.read()
print(html)

Any help?

도와주세요.

 

 

 높은 점수를 받은 Solution 

As stated in the urllib2 documentation:

urllib2 설명서에 명시된 바와 같이:

 

The urllib2 module has been split across several modules in Python 3 named urllib.request and urllib.error. The 2to3 tool will automatically adapt imports when converting your sources to Python 3.

urllib2 모듈은 파이썬 3에서 urllib.request 및 urllib.error라는 이름의 여러 모듈로 분할되었습니다. 2 to 3 도구는 소스를 파이썬 3으로 변환할 때 자동으로 가져오기를 조정합니다.

 

So you should instead be saying

그래서 대신에 당신은 말해야 한다.

 

from urllib.request import urlopen
html = urlopen("http://www.google.com/").read()
print(html)

Your current, now-edited code sample is incorrect because you are saying urllib.urlopen("http://www.google.com/") instead of just urlopen("http://www.google.com/").

당신이 단지 urlopen(http://www.google.com/") 대신 urllib.urlopen(http://www.google.com/")이라고 말하고 있기 때문에 당신의 현재의 현재 코드 샘플은 부정확하다.

 

 

 

 가장 최근 달린 Solution 

Instead of using:

다음을 사용하는 대신:

 

import urllib2

use code below in python3

python3에서 아래 코드를 사용합니다.

 

import urllib.request as urllib2

 

 

출처 : https://stackoverflow.com/questions/2792650/import-error-no-module-name-urllib2

반응형
댓글
공지사항
최근에 올라온 글